Variables Questions and Answers

Practice Mode
Showing 10 of 24 questions
Q1
Which of the following is a valid variable name in Python?
  • A 2var
  • B _var
  • C var-name
  • D var name
Answer: Option B
Explanation: Variable names cannot start with numbers or contain special characters except underscore.
Q2
What is the output of: x = 5; print(type(x))?
  • A <class 'int'>
  • B <class 'str'>
  • C <class 'float'>
  • D <class 'number'>
Answer: Option A
Explanation: The type() function returns the data type of a variable.
Q3
Which keyword is used to declare a variable in Python?
  • A var
  • B variable
  • C No keyword needed
  • D declare
Answer: Option C
Explanation: Python variables are declared by simply assigning a value, no special keyword is needed.
Q4
What will be the value of y after: x = 10; y = x?
  • A 10
  • B x
  • C y
  • D None
Answer: Option A
Explanation: Assignment operator copies the value from one variable to another.
Q5
Which of these is NOT a valid data type in Python?
  • A int
  • B str
  • C double
  • D bool
Answer: Option C
Explanation: All except "double" are valid Python data types. Python uses "float" for decimal numbers.
Q6
What does the id() function return for a variable?
  • A Variable name
  • B Variable value
  • C Memory address
  • D Data type
Answer: Option C
Explanation: id() returns the memory address where the variable is stored.
Q7
How do you swap the values of two variables in Python?
  • A a, b = b, a
  • B swap(a, b)
  • C a = b; b = a
  • D temp = a; a = b; b = temp
Answer: Option A
Explanation: Python allows multiple assignment for easy variable swapping.
Q8
What is the scope of a variable defined inside a function?
  • A Global
  • B Local
  • C Class
  • D Module
Answer: Option B
Explanation: Variables inside functions have local scope by default.
Q9
Which operator is used for checking if two variables point to the same object?
  • A ==
  • B =
  • C is
  • D same
Answer: Option C
Explanation: The "is" operator checks object identity, while "==" checks value equality.
Q10
What is a global variable in Python?
  • A Variable defined inside a function
  • B Variable defined in the main program
  • C Variable that cannot be changed
  • D Temporary variable
Answer: Option B
Explanation: Global variables are accessible throughout the program, outside any function.
Questions and Answers for Competitive Exams Various Entrance Test