Python MCQs Variables

Q1. What is a variable in Python?

A) A keyword
B) A data type
C) A memory location used to store a value
D) A function
✅ Correct Answer: (C) A memory location used to store a value
📘 Explanation: A variable stores data values in memory and can change during program execution.

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

A) 1value
B) value-1
C) value_1
D) value 1
✅ Correct Answer: (C) value_1
📘 Explanation: Variable names can contain letters, numbers, and underscores but cannot start with a number or contain spaces/special symbols.

Q3. Which symbol is used to assign a value to a variable in Python?

A) ==
B) =
C) :=
D) !=
✅ Correct Answer: (B) =
📘 Explanation: The single equals sign = is used for assignment in Python.

Q4. Which of the following variable names is NOT valid?

A) total_marksl
B) _count
C) count2
D) total-marks
✅ Correct Answer: (D) total-marks
📘 Explanation: Hyphen (-) is not allowed in Python variable names.

Q5. Python is a ______ typed language.

A) Static
B) Strong
C) Dynamic
D) Weak
✅ Correct Answer: (C) Dynamic
📘 Explanation: Python uses dynamic typing, so variable types are decided at runtime.

Q6. Which keyword is used to declare a variable in Python?

A) var
B) int
C) declare
D) None of the above
✅ Correct Answer: (D) None of the above
📘 Explanation: Python does not require a keyword to declare variables.

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


x = 10
x = “Hello”
print(x)

A) 10
B) Hello
C) Error
D) None
✅ Correct Answer: (B) Hello
📘 Explanation: Python allows reassignment of variables to different data types.

Q8. Which of the following is used to check the data type of a variable?

A) datatype()
B) type()
C) check()
D) isinstance()
✅ Correct Answer: (B) type()
📘 Explanation: The type() function returns the data type of a variable.

Q9. Which of the following is a case-sensitive variable name?

A) value and VALUE
B) value and Value
C) Both A and B
D) None
✅ Correct Answer: (C) Both A and B
📘 Explanation: Python is case-sensitive, so value, Value, and VALUE are different variables.

Q10. What is the correct way to assign multiple values to variables?

A) x = 1, y = 2
B) x, y = 1, 2
C) x = y = 1, 2
D) assign x, y = 1, 2
✅ Correct Answer: (B) x, y = 1, 2
📘 Explanation: Python allows multiple assignment using x, y = 1, 2.

Q11. Which of the following statements is correct about Python variables?

A) Variables must be declared before use
B) Variables store only numbers
C) Variables can change their data type during execution
D) Variables are fixed in size
✅ Correct Answer: (C) Variables can change their data type during execution
📘 Explanation: Python allows variables to be reassigned with values of different data types.

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


a = 5
b = a
a = 10
print(b)

A) 5
B) 10
C) Error
D) None
✅ Correct Answer: (A) 5
📘 Explanation: b gets the value of a at assignment time. Later changes to a do not affect b.

Q13. Which of the following is used to delete a variable in Python?

A) remove
B) delete
C) del
D) clear
✅ Correct Answer: (C) del
📘 Explanation: The del keyword deletes a variable or object reference..

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


x = y = z = 100
print(x, y, z)

A) 100
B) 100 100
C) 100 100 100
D) Error
✅ Correct Answer: (C) 100 100 100
📘 Explanation: Python allows assigning the same value to multiple variables.

Q15. Which of the following cannot be used as a variable name?

A) value
B) value123
C) for
D) value
✅ Correct Answer: (C) for
📘 Explanation: for is a Python keyword and cannot be used as a variable name.

Q16. What will be the output?


x = 5
print(type(x))

A) int
B) float
C) str
D) number
✅ Correct Answer: (A) int
📘 Explanation: The type() function returns the class of the variable.

Q17. Which of the following statements about variable scope is TRUE?

A) Global variables are accessible everywhere
B) Local variables are accessible outside the function
C) Global variables must be declared inside a function
D) Local variables are accessible everywhere
✅ Correct Answer: (A) Global variables are accessible everywhere
📘 Explanation: Global variables can be accessed inside and outside functions.

Q18. What does the id() function return?

A) Variable name
B) Memory address of the object
C) Data type
D) Value
✅ Correct Answer: (B) Memory address of the object
📘 Explanation: id() returns the unique identity (memory location) of an object.

Q19. Which of the following is an example of unpacking variables?

A) x = 10
B) x, y = 1, 2
C) x = y = 10
D) assign x, y
✅ Correct Answer: (B) x, y = 1, 2
📘 Explanation: Unpacking assigns multiple values to multiple variables in one statement.

Q20. What happens when a variable is assigned a new value in Python?

A) Old value remains in memory
B) Variable name changes
C) Variable now refers to a new object
D) Program gives an error
✅ Correct Answer: (C) Variable now refers to a new object
📘 Explanation: In Python, variables are references. Reassignment makes the variable point to a new object.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top