Python int() vs float() Error

Which of the following Python expressions will result in an error? 🤔 Understanding type conversion (int() vs float()) is a small but important part of writing clean Python code. Drop your answer in the comments 👇 Let’s keep learning, one concept at a time! 🚀🐍 #Python #PythonBasics #MCQ #Coding #Learning #Programming #DeveloperLife

  • text

Correct answer: D) int('12.5') int() cannot parse a string containing a decimal point. It only accepts strings that represent whole numbers. To convert '12.5' to an integer, you must first convert it to float:

Like
Reply

Answer is D. Because, int() cannot parse a string with decimal points. It only allows strings with integer numbers.

Like
Reply

int('12.5') because it is a float.

Like
Reply

result = int(float('12.5')) print(result) Output: 12

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories