Page 302 - Computer Science Class 11 Without Functions
P. 302

Say Y/y for yes, N/n for no:y
         >>> Enter roll no for marks update: 505
         >>> Enter revised marks for update: 33
              Continue another update?
              Say Y/y for yes, N/n for no:y
         >>> Enter roll no for marks update: 501
         >>> Enter revised marks for update: 60
              Continue another update?
              Say Y/y for yes, N/n for no:n
              Moderated result:
              [[501, 60], [503, 55], [504, 46], [505, 33]]
        12.10 Tuples

        A tuple is a sequence of elements, separated by commas and usually enclosed between parentheses. For example,
         >>> bDate = (30, 'September', 1987)
         >>> bDate
              (30, 'September', 1987)
        It is perfectly fine to drop the parentheses around the comma separated values. For example,
         >>> bDate = 30, 'September', 1987
         >>> bDate
              (30, 'September', 1987)
        An empty pair of parentheses defines an empty tuple, for example,

         >>> emptyTuple = ()    # or emptyTuple = tuple()
         >>> type(emptyTuple)
              <class 'tuple'>
        Interestingly, a single value enclosed in parentheses does not define a tuple as it is interpreted as an expression
        enclosed in a pair of parentheses. For example,
         >>> republic = (1950)
         >>> type(republic)
              <class 'int'>
         >>> republic
              1950
        To express a tuple comprising a single value, the value in the tuple is followed by a comma, For example,
         >>> republic = (1950,)
         >>> republic
              (1950,)
        Examine the following:

         >>> t1 = (2, 4, 6)
         >>> t2 = (2, 4, 6)
         >>> print('id(t1):', id(t1), 'id(t2):', id(t2) )
              id(t1): 2402511302272 id(t2): 2402547197696
         >>> t1 is t2
              False
         >>> t1 == t2
              True
        Note that the two assignment statements create two different instances of tuples. Therefore,  the expression t1 is
        t2 yields False. However, as t1 and t2 comprise the same sequence of elements, the expression t1 == t2
        yields True.
        12.10.1 Deriving a Tuple from a String/ List/ Set

        The function tuple() is used to construct a tuple from a string, list, or set. For example,
         >>> vowels = 'aeiou'
         >>> vowels1 = tuple(vowels)

         300   Touchpad Computer Science-XI
   297   298   299   300   301   302   303   304   305   306   307