Variables Questions and Answers
Practice ModeShowing 10 of 24 questions
Q1
Which of the following is a valid variable name in Python?
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))?
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?
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?
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?
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?
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?
Answer: Option A
Explanation: Python allows multiple assignment for easy variable swapping.
Q8
What is the scope of a variable defined inside a function?
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?
Answer: Option C
Explanation: The "is" operator checks object identity, while "==" checks value equality.
Q10
What is a global variable in Python?
Answer: Option B
Explanation: Global variables are accessible throughout the program, outside any function.