Bird
0
0

What is the issue with this Python code?

medium📝 Debug Q7 of 15
Python - Variables and Dynamic Typing
What is the issue with this Python code?
num = 7
num = num + [3]
print(num)
ATypeError: unsupported operand types for +: 'int' and 'list'
BThe code runs and prints [10]
CThe code runs and prints 73
DSyntaxError due to invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Initial Type

    num is an integer with value 7.
  2. Step 2: Adding List

    Attempting to add a list [3] to an integer causes a TypeError because these types cannot be added.
  3. Final Answer:

    TypeError -> Option A
  4. Quick Check:

    Cannot add int and list directly in Python. [OK]
Quick Trick: int + list causes TypeError [OK]
Common Mistakes:
MISTAKES
  • Assuming Python concatenates int and list
  • Expecting implicit type conversion
  • Confusing list addition with integer addition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes