Week 2
Week 2: Data Structures & Exception Handling
1. Lists, Tuples, Dictionaries, Sets
my_list = [1, 2, 3, 4, 5] my_list.append(6) # Add an element my_list.remove(2) # Remove an element print(my_list) # Output: [1, 3, 4, 5, 6]numbers = [10, 20, 30, 40, 50] print(numbers[1]) # Output: 20 print(numbers[-1]) # Output: 50 print(numbers[1:4]) # Output: [20, 30, 40]
my_tuple = (1, 2, 3, 4) print(my_tuple[1]) # Output: 2my_tuple = (10, 20, 30) # my_tuple[0] = 100 # This will raise an error since tuples are immutable
2. List & Dictionary Comprehensions
3. Exception Handling (try-except-finally)
4. File Handling (Reading/Writing Files, CSV, JSON)
Last updated