Variables Questions and Answers
Python Programming - Variables Questions with Answers help understand how data is stored and referenced in Python. These Python Variables Questions are key for Infosys, Accenture, and SSC exams testing programming basics and naming conventions
Variables
Showing 10 of
24 questions
1. Which of the following is a valid variable name in Python?
- 2var
- _var
- var-name
- var name
2. What is the output of: x = 5; print(type(x))?
- <class 'int'>
- <class 'str'>
- <class 'float'>
- <class 'number'>
3. Which keyword is used to declare a variable in Python?
- var
- variable
- No keyword needed
- declare
6. What does the id() function return for a variable?
- Variable name
- Variable value
- Memory address
- Data type
7. How do you swap the values of two variables in Python?
- a, b = b, a
- swap(a, b)
- a = b; b = a
- temp = a; a = b; b = temp
8. What is the scope of a variable defined inside a function?
- Global
- Local
- Class
- Module
9. Which operator is used for checking if two variables point to the same object?
- ==
- =
- is
- same
10. What is a global variable in Python?
- Variable defined inside a function
- Variable defined in the main program
- Variable that cannot be changed
- Temporary variable