Variables Questions and Answers

Practice Mode
Showing 10 of 24 questions
Q11
How do you delete a variable in Python?
  • A remove()
  • B delete()
  • C del
  • D clear()
Answer: Option C
Explanation: The del statement removes variable references from memory.
Q12
What is the output of: a = [1, 2, 3]; b = a; b[0] = 5; print(a)?
  • A [1, 2, 3]
  • B [5, 2, 3]
  • C [1, 2, 3, 5]
  • D Error
Answer: Option B
Explanation: Lists are mutable and assignment creates a reference, not a copy.
Q13
Which of these is an immutable data type in Python?
  • A list
  • B dict
  • C tuple
  • D set
Answer: Option C
Explanation: Tuples are immutable, meaning their values cannot be changed after creation.
Q14
What does the None keyword represent in Python?
  • A Zero
  • B Empty string
  • C Null value
  • D Boolean false
Answer: Option C
Explanation: None is a special constant representing the absence of a value.
Q15
How do you create a constant variable in Python?
  • A const PI = 3.14
  • B final PI = 3.14
  • C PI = 3.14
  • D Use uppercase naming convention
Answer: Option D
Explanation: Python doesn't have built-in constants, but uppercase naming convention is used.
Q16
What is variable shadowing in Python?
  • A When a variable changes type
  • B When local and global variables have same name
  • C When a variable is deleted
  • D When a variable is undefined
Answer: Option B
Explanation: Variable shadowing occurs when a local variable has the same name as a global variable.
Q17
Which function converts a string to an integer in Python?
  • A str()
  • B int()
  • C integer()
  • D to_int()
Answer: Option B
Explanation: int() function converts strings and other types to integers.
Q18
What is the lifetime of a local variable in Python?
  • A Entire program execution
  • B Only during function execution
  • C Until manually deleted
  • D One minute
Answer: Option B
Explanation: Local variables exist only during function execution.
Q19
How do you check if a variable is defined in Python?
  • A try-except block
  • B if variable exists:
  • C Check in locals() or globals()
  • D is_defined() function
Answer: Option C
Explanation: The locals() and globals() functions contain current variable definitions.
Q20
What is the difference between = and == in Python?
  • A No difference
  • B = compares, == assigns
  • C = assigns, == compares
  • D Both are assignment operators
Answer: Option C
Explanation: = is for assignment, == is for equality comparison.
Questions and Answers for Competitive Exams Various Entrance Test