Page 85 - Information_Practice_Fliipbook_Class11
P. 85

>>> vowels = ('a','e','i','o','u')
                     ('a', 'e', 'i', 'o', 'u')
             >>> weekDays = ('Monday', 'Tusday', 'Wednesday', 'Thursday', 'Friday')
             >>> weekDays
                     ('Monday', 'Tusday', 'Wednesday', 'Thursday', 'Friday')
            On realising that you wrongly typed Tuesday, it would be tempting to modify weekDays[1] to 'Tuesday'
             >>> weekDays[1] = 'Tuesday'
                     Traceback (most recent call last):
                       File "<pyshell#101>", line 1, in <module>
                         weekDays[1] =  'Tuesday'
                     TypeError: 'tuple' object does not support item assignment
            Note that an attempt to modify an element of a tuple has resulted in a type error because we have applied an illegal
            operation to a tuple.

            4.1.4 Set

            A  set  is  an  unordered  and  unindexed  collection  of  data  items  separated  by  a  comma  and  enclosed  within  curly
            brackets:{}. Unlike a list, a set cannot have duplicate values. For example,
             >>> set1 = {1, 2, 3, 4}
             >>> set1
                 {1, 2, 3, 4}
             >>> set2 = {1, 2, 3, 5, 1, 6, 2}
             >>> set2
                 {1, 2, 3, 5, 6}
            Note that the duplicate entries in set2 have been removed. A set may be modified using the operator |=. As follows:
             >>> s = {1, 29, 4}
             >>> id(s)
                     2309188291712
             >>> s |= {54, 9}
             >>> s
                     {1, 4, 54, 9, 29}
             >>> id(s)
                     2309188291712
             4.1.5 None

            NoneType has a single value: None. It is used to signify the absence of value in a given statement. None supports
            no special operations. The value of None is neither False nor 0 (zero). Consider the following examples:
             >>> type(None)
                 <class 'NoneType'>
             >>> print(None)
                 None
            However, if you execute the command,
            None

            Nothing is printed. In a logical expression, the value of None is False.
            4.1.6 Dictionary (Mapping)

            A dictionary (dict) is an unordered set of key-value pairs enclosed in curly brackets:{}. It maps a set of keys to a set
            of values. The key is separated from its value using a colon(:), and  key-value pairs are separated from each other by
            commas (,). A dictionary does not allow repeated keys.

             >>> furniturePrice = {'chair':500, 'table': 2000, 'stool':1000}
             >>> furniturePrice
                     {'chair': 500, 'table': 2000, 'stool': 1000}
             >>> furniturePrice['table']
                     2000

                                                                                        Data Types and Operators  71
   80   81   82   83   84   85   86   87   88   89   90