I have written the following code:
typConvInt = int('3.3')
print(typConvInt)
But compiler is throwing an error.
ErrorMessage:
Traceback (most recent call last):
File "E:\Trainings\Python_Training\HelloWorld.py", line 285, in <module>
intconv3 = int('3.3')
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '3.3'
Version: Python 2.7.7
I tried to change the float to integer value it worked but it still failing with the float string to integer conversion
conv1 = int('3')
print(conv1)
# this is passed
conv2 = int('3.0')
print(conv2)
# this code is still failing but the tutorial says this will work and return as 3
Documentation: https://docs.python.org/3/library/stdtypes.html
typConvInt = int(3.3)
<== remove string. If you want print 3.3 thenfloat(3.3)
will do.