Variables, Types & Operators · Question 1 · Easy

The name x is first bound to a number and then to text. What does this snippet print?

x = 10
x = "ten"
print(type(x).__name__)
  1. str
  2. int
  3. TypeError
  4. NameError
Answer and explanation

Answer: A. str

Explanation: Python is dynamically typed: a name has no fixed type, it simply refers to whatever object was assigned last. After the second assignment x refers to a string, so its type is str.

Next: Riya shares 17 chocolates equally among 5 friends and keeps the leftovers…

Practise variables, types & operators

Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.

More variables, types & operators questions

More python practice

Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge