Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Python - Variables and Dynamic Typing
What is wrong with this code?
data = 3.5
if type(data) == 'float':
    print("Float detected")
AComparing type to string instead of type object
BMissing colon after if statement
CUsing '==' instead of 'is' for type comparison
DNo error, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check the comparison in if condition

    The code compares type(data) to the string 'float', which is incorrect.
  2. Step 2: Correct comparison should be to the type object

    Use float (without quotes) to compare types, not the string 'float'.
  3. Final Answer:

    Comparing type to string instead of type object -> Option A
  4. Quick Check:

    Compare type() to type objects, not strings [OK]
Quick Trick: Compare to type objects like float, not strings 'float' [OK]
Common Mistakes:
MISTAKES
  • Comparing to string instead of type
  • Missing colon in if statement
  • Using 'is' incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes