✏️ Explanatory Question

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?

👁 304 Views
📘 Detailed Answer
304
Total Views
10
Related Qs
0%
Progress
💡

Answer with Explanation

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.