Python_Viva_Questions
Python_Viva_Questions
### Looping
8. What are the differences between for and while loops in Python?
- A for loop is used when the number of iterations is known
beforehand (e.g., iterating over a list). A while loop is used when the
number of iterations depends on a condition.
### Lists
14. How do you declare a list in Python?
- Using square brackets:
my_list = [1, 2, 3]
### Tuples
17. What is the difference between a list and a tuple?
- A list is mutable (modifiable), while a tuple is immutable (cannot
be modified).
### Dictionaries
19. What is a dictionary in Python?
- A dictionary is a collection of key-value pairs.
Example:
my_dict = {"name": "John", "age": 30}
### Functions
21. What are the types of functions in Python?
- Built-in functions and user-defined functions.
### Modules
24. How do you import a module in Python?
- Using the import keyword.
import math
print(math.sqrt(16))