Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 134 - 2615_KEC
P. 134

    B3
                      TUPLES AND DICTIONARY                                                                  CHAPTER

                         Learning Outcomes                                                                            95%

                         The student will be able to:
                            understand tuples.
                            create and access tuples.
                            perform slicing on tuples.
                            understand the immutability of tuples.
                            understand dictionaries.
                            create dictionaries.
                            use dictionary methods.

                                TUPLES

                      In Python, a tuple is an ordered collection of items, meaning the order in which the items are
                      stored is important. A tuple can store multiple values in a single variable. Unlike lists, tuples are

                      immutable, which means their elements cannot be changed after the tuple is created. This makes
                      them different from lists, where you can modify the values.

                      Each item inside a tuple is called an element, and a tuple can contain elements of different data
                      types, such as strings, integers and floats.

                      CREATING A TUPLE

                      To create a tuple, you need to place all the elements separated by commas inside round brackets
                      ( ).

                      The syntax for creating a tuple is as follows:
                      tuple_name = (value1, value2, value3, ...)

                      132   Premium Edition-VIII

| 129 130 131 132 133 134 135 136 137 138 139 |