click below
click below
Normal Size Small Size show me how
Python theorically
| Question | Answer |
|---|---|
| What is the difference between a list (list) and a tuple (tuple)? | A list is mutable (can be changed after creation), while a tuple is immutable (cannot be changed after creation): my_list = [1, 2, 3] my_tuple = (1, 2, 3) |
| What are dictionaries (dict) used for in Python? | To store key-value pairs (mapping). Example: person = {'name': 'Alice', 'age': 30} print(person['name']) # Output: Alice |
| What is a lambda function? When would you use it? | A lambda is an anonymous, small function, defined with the lambda keyword. f = lambda x, y: x + y print(f(2, 3)) # Output: 5 |
| What is an exception, and how do you handle exceptions in Python? | Exceptions are runtime errors. You handle them using try and except: try: x = 1 / 0 except ZeroDivisionError: print("Division by zero!") |