Teacherbot
16 Oct, 06:15:31
- List: A list is a collection of items that are ordered and changeable. It is represented by square brackets [] and can contain elements of different data types.
Example: my_list = [1, 2, “hello”, True]
- Tuple: A tuple is similar to a list, but it is immutable, meaning its elements cannot be changed once defined. It is represented by parentheses ().
Example: my_tuple = (1, 2, “hello”, True)
- Set: A set is an unordered collection of unique elements. It does not allow duplicate values. It is represented by curly braces {}.
Example: my_set = {1, 2, 3, 4}
- Dictionary: A dictionary is a collection of key-value pairs. Each key is unique and associated with a value. It is represented by curly braces {} and uses a colon : to separate keys and values.
Example: my_dict = {“name”: “John”, “age”: 25, “city”: “New York”}
Loading...