Learn with Yasir

Share Your Feedback

Python Variables MCQs | Multiple Choice Practice & Progress

Test and enhance your Python skills with variable-focused MCQs! Cover declaration, assignment, naming conventions, scope, and common errors through interactive multiple‑choice questions.

Topic: variables


πŸ“ Multiple Choice Questions

🟒 Beginner

Q1. What is a variable in Python?

  • 🟒 A. A reserved word in Python
  • πŸ”΅ B. A placeholder for storing data values
  • 🟠 C. A function that prints data
  • πŸ”΄ D. A built-in library in Python
Answer

A placeholder for storing data values

A variable acts as a container to store data values in memory.


Q2. Which statement best describes a variable in Python?

  • 🟒 A. A variable can hold multiple values at once.
  • πŸ”΅ B. A variable must be declared with a data type.
  • 🟠 C. A variable is a name that refers to a value.
  • πŸ”΄ D. A variable is used only in loops.
Answer

A variable is a name that refers to a value.

In Python, variables are simply names that reference objects in memory.


Q3. What is the output of the following code?

x = 10
print(x)
  • 🟒 A. 10
  • πŸ”΅ B. x
  • 🟠 C. Error
  • πŸ”΄ D. None
Answer

10

The code assigns 10 to x and then prints the value of x.


Q4. Why is it important to use meaningful variable names?

  • 🟒 A. It is required by the Python interpreter.
  • πŸ”΅ B. It helps make the code more readable and maintainable.
  • 🟠 C. It increases the execution speed of the program.
  • πŸ”΄ D. It is necessary for the code to run without errors.
Answer

It helps make the code more readable and maintainable.

Good variable names improve code understanding without affecting functionality.


Q5. Which of the following is a valid variable name in Python?

  • 🟒 A. 2ndValue
  • πŸ”΅ B. value#2
  • 🟠 C. _value2
  • πŸ”΄ D. value-2
Answer

_value2

Valid names start with letters/underscores and contain alphanumerics/underscores.


Q6. Which of the following is a correct way to declare a variable in Python?

  • 🟒 A. int x = 5
  • πŸ”΅ B. x = 5
  • 🟠 C. declare x = 5
  • πŸ”΄ D. var x = 5
Answer

x = 5

Python uses dynamic typing - just assign with = operator.


Q7. Which of the following is not a valid variable name in Python?

  • 🟒 A. my_var
  • πŸ”΅ B. _var
  • 🟠 C. 2var
  • πŸ”΄ D. var2
Answer

2var

Variable names cannot start with numbers.


Q8. What is the purpose of declaring a variable in Python?

  • 🟒 A. To reserve memory space for the variable
  • πŸ”΅ B. To give the variable a name
  • 🟠 C. To initialize the variable with a value
  • πŸ”΄ D. All of the above
Answer

All of the above

Variable declaration achieves all these purposes simultaneously.


Q9. What is dynamic typing in Python?

  • 🟒 A. Variables must be declared with a fixed data type.
  • πŸ”΅ B. Variables can change their type during runtime.
  • 🟠 C. Python enforces strict type checking at compile time.
  • πŸ”΄ D. Variables cannot be reassigned.
Answer

Variables can change their type during runtime.

Python allows variables to hold values of any type and change types dynamically.


Q10. What is the output of the following code?

x = 10
x = "Hello"
print(type(x))
  • 🟒 A. <class 'int'>
  • πŸ”΅ B. <class 'str'>
  • 🟠 C. Error
  • πŸ”΄ D. None
Answer

<class 'str'>

Python allows reassigning `x` from an integer to a string (dynamic typing).


Q11. What does `None` represent in Python?

  • 🟒 A. A zero value
  • πŸ”΅ B. An empty string
  • 🟠 C. The absence of a value
  • πŸ”΄ D. A placeholder for future use
Answer

The absence of a value

`None` signifies <b>no value</b> or <b>null</b> in Python.


Q12. Which of the following is a valid use of `None`?

  • 🟒 A. As a default function argument
  • πŸ”΅ B. To represent an uninitialized variable
  • 🟠 C. To check if a key exists in a dictionary
  • πŸ”΄ D. All of the above
Answer

All of the above

`None` is commonly used for all these purposes.


🟑 Intermediate

Q1. Which of the following is not true about variables in Python?

  • 🟒 A. Variables can be reassigned to different data types.
  • πŸ”΅ B. Variables must start with a letter or an underscore.
  • 🟠 C. Variables are case-sensitive.
  • πŸ”΄ D. Variables must be declared before use.
Answer

Variables must be declared before use.

Python variables don't need declaration; they're created when first assigned.


Q2. What will be the output of the following code?

x = 5
y = x
x = 7
print(y)
  • 🟒 A. 7
  • πŸ”΅ B. 5
  • 🟠 C. 0
  • πŸ”΄ D. None
Answer

5

y gets the value of x (5) before x is changed to 7.


Q3. What will be the output of the following code?

a = 1
b = a
a = a + 1
print(a, b)
  • 🟒 A. 1 1
  • πŸ”΅ B. 2 1
  • 🟠 C. 1 2
  • πŸ”΄ D. 2 2
Answer

2 1

b gets the original value of a (1), then a is incremented to 2.


Q4. What is the output of the following code?

x = 5
y = "Hello"
print(x + y)
  • 🟒 A. 5Hello
  • πŸ”΅ B. Hello5
  • 🟠 C. TypeError
  • πŸ”΄ D. Hello 5
Answer

TypeError

Python cannot implicitly concatenate different types (int + str).


Q5. Which of the following statements is true about variable assignment in Python?

  • 🟒 A. Variables must be declared before they are assigned a value.
  • πŸ”΅ B. Variables are created when they are first assigned a value.
  • 🟠 C. Variable names must begin with a number.
  • πŸ”΄ D. Python variables must be declared with a type.
Answer

Variables are created when they are first assigned a value.

Python variables come into existence at first assignment.


Q6. Which of the following is true about Python's type system?

  • 🟒 A. Python is statically typed.
  • πŸ”΅ B. Python variables must be declared with a type.
  • 🟠 C. Python checks types at runtime (dynamic typing).
  • πŸ”΄ D. Python does not allow reassigning variables.
Answer

Python checks types at runtime (dynamic typing).

Python resolves types during execution, not at compile time.


Q7. What is the output of the following code?

x = None
print(x is None)
  • 🟒 A. True
  • πŸ”΅ B. False
  • 🟠 C. Error
  • πŸ”΄ D. None
Answer

True

`None` is a singleton in Python, and `is` checks for identity.


Q8. What is the output of the following code?

def foo():
    pass
print(foo())
  • 🟒 A. None
  • πŸ”΅ B. Error
  • 🟠 C. 0
  • πŸ”΄ D. pass
Answer

None

A function without a `return` statement implicitly returns `None`.


Q9. How do you check if a variable is `None` in Python?

  • 🟒 A. if x == None:
  • πŸ”΅ B. if x is None:
  • 🟠 C. if x = None:
  • πŸ”΄ D. if None in x:
Answer

if x is None:

`is` is preferred over `==` for `None` checks (identity vs. equality).


Q10. What is the output of the following code?

x = None
y = None
print(x == y, x is y)
  • 🟒 A. True True
  • πŸ”΅ B. False False
  • 🟠 C. True False
  • πŸ”΄ D. Error
Answer

True True

`None == None` is `True`, and `None is None` is also `True` (same object).


Q11. What is the output of the following code?

x = "Hello"
x = None
print(x)
  • 🟒 A. Hello
  • πŸ”΅ B. None
  • 🟠 C. Error
  • πŸ”΄ D. null
Answer

None

`x` is reassigned to `None`, which is printed.


πŸ”΄ Advanced

Q1. What is the output of the following code?

x = [None, 1, "two"]
print(type(x[0]))
  • 🟒 A. <class 'NoneType'>
  • πŸ”΅ B. <class 'int'>
  • 🟠 C. <class 'str'>
  • πŸ”΄ D. Error
Answer

<class 'NoneType'>

`None` has its own type, `NoneType`.


Q2. What is the output of the following code?

def bar():
    return None
print(bar() is None)
  • 🟒 A. True
  • πŸ”΅ B. False
  • 🟠 C. Error
  • πŸ”΄ D. None
Answer

True

Explicitly returning `None` is the same as no `return` statement.