Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
Python - Data Types as Values

What is the output of the following code?

x = 7 / 2
print(type(x))
print(x)
A<class 'int'>\n3.5
B<class 'int'>\n3
C<class 'float'>\n3.5
DSyntaxError
Step-by-Step Solution
Solution:
  1. Step 1: Understand division operator in Python 3

    Division with / always returns a float, even if numbers divide evenly.
  2. Step 2: Evaluate the code

    7 / 2 = 3.5, which is a float. So type(x) is <class 'float'> and x is 3.5.
  3. Final Answer:

    <class 'float'>\n3.5 -> Option C
  4. Quick Check:

    7 / 2 = 3.5 float [OK]
Quick Trick: Division / always returns float in Python 3 [OK]
Common Mistakes:
MISTAKES
  • Assuming integer division with /
  • Confusing type output format
  • Expecting 3 instead of 3.5

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes