Lists: Lists are ordered collections that can contain elements of different types. They are mutable, meaning you can change their elements. Example: python Copy code my_list = [1, 2, "apple", True] my_list.append(5) # Adding an element print(my_list[2]) # Accessing an element by index my_list.remove("apple") # Removing an element print(my_list) # Printing the modified list Dictionary: Dictionaries are unordered collections of key-value pairs. They use keys to access their associated values and are mutable. Example: python Copy code my_dict = {"name": "Alice", "age": 25, "city": "New York"} print(my_dict["age"]) # Accessing value by key my_dict["occupation"] = "Engineer" # Adding a new key-value pair del my_dict["city"] # Deleting a key-value pair print(my_dict) # Printing the modified dictionary Ranges: Ranges are sequences of numbers used for iterating over a sequence...
ความคิดเห็น
แสดงความคิดเห็น