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
Answer is D. Because, int() cannot parse a string with decimal points. It only allows strings with integer numbers.
int('12.5') because it is a float.
result = int(float('12.5')) print(result) Output: 12
Int 12.5 ?
Option D
Option D
D
D
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: