Bird
0
0

Given this code, what will be the output?

hard📝 Application Q9 of 15
Python - Variables and Dynamic Typing
Given this code, what will be the output?
items = [1, 'two', 3.0, True]
types = [type(i) for i in items]
print(types)
A[<class 'int'>, <class 'str'>, <class 'float'>, <class 'bool'>]
B[int, str, float, bool]
C['int', 'str', 'float', 'bool']
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand list comprehension with type()

    type(i) returns the type object for each item in list.
  2. Step 2: Check print output format

    Printing list of type objects shows <class 'type'> format for each.
  3. Final Answer:

    [<class 'int'>, <class 'str'>, <class 'float'>, <class 'bool'>] -> Option A
  4. Quick Check:

    type() returns type objects shown as <class '...'> [OK]
Quick Trick: type() returns type objects shown as <class '...'> [OK]
Common Mistakes:
MISTAKES
  • Expecting string names instead of type objects
  • Confusing type objects with strings
  • Assuming error due to mixed types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes