What will the following command display? print("fractional string to int:", int ("3.4")) State the reason for getting the output and what is required to be done?

Python >   Fundamentals of Python >   Important Points about Python  

Short Question

321


Answer:

Ans. The above statement, upon execution, shall result in an error since Python int command cannot convert the string "3.4" into 3.4 as Python cannot perform two consecutive typecasts, therefore, you must convert it explicitly in code. This statement is to be modified such as: int(float("3.4")) which shall generate the output as 3.


This Particular section is dedicated to Question & Answer only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.