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
12. What is the output of: a = [1, 2, 3]; b = a; b[0] = 5; print(a)?
- [1, 2, 3]
- [5, 2, 3]
- [1, 2, 3, 5]
- Error
14. What does the None keyword represent in Python?
- Zero
- Empty string
- Null value
- Boolean false
15. How do you create a constant variable in Python?
- const PI = 3.14
- final PI = 3.14
- PI = 3.14
- Use uppercase naming convention
16. What is variable shadowing in Python?
- When a variable changes type
- When local and global variables have same name
- When a variable is deleted
- When a variable is undefined
17. Which function converts a string to an integer in Python?
- str()
- int()
- integer()
- to_int()
18. What is the lifetime of a local variable in Python?
- Entire program execution
- Only during function execution
- Until manually deleted
- One minute
19. How do you check if a variable is defined in Python?
- try-except block
- if variable exists:
- Check in locals() or globals()
- is_defined() function
20. What is the difference between = and == in Python?
- No difference
- = compares, == assigns
- = assigns, == compares
- Both are assignment operators