I thought 0.5
would come out if I said 1/2
, but 0
came out
If you divide two integers, you just cut off the decimal point
When a and b are int
c = a/b
How do we get c to float as a result?
a = 1
b = 2
print a/b
division import
modules.
from__future__import division #Not required for Python 3 or higher
print 1/2
If you do not write __future___
, you can write as follows.
However, this method can cause TypeError
, so use it carefully.
a = 1
b = 2
float(a)/float(b)
You can use it with this
* Python 3 saves the result of int
/int
as float
. So you don't have to import anything, and you don't have to change the type.
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
581 PHP ssh2_scp_send fails to send files as intended
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.