Can you explain the following circumstances in python3? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you explain the following circumstances in python3?

why does typecasting of string into integer work in the following code x=int(input("enter no.") while it doesn't work in this one: print(int("4.5"))

24th Jul 2018, 4:09 AM
Ajai Kannan. K
Ajai Kannan. K - avatar
2 Answers
+ 3
If your input is 4.5 (is a float) you will get the same error on the input line.
24th Jul 2018, 6:33 AM
Paul
Paul - avatar
+ 1
4.5 is real value so you have to use float here. print(float("4.5"))
24th Jul 2018, 5:42 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar