Page 176 - Computer Science V2.0 Class 11
P. 176

Finally, clicking <Next> twice displays the object id of two lists, lst1 and lst2, in the Print Output box (Fig 7.18).
























                                  Fig 7.18: Code Visualization through Python Tutor (after execution of line 7 and 8)


              7.4 Usage of Python Data Types

              To perform arithmetic computations, we use numeric data types such as integers (int) and floating point numbers
              (float). Strings (str) are used to deal with textual data. We use a list when several data items have to be stored.
              For example, the details of marks of several students in an examination may be stored in a list. A tuple is used to store
              several data values when the collection of items does not need to be modified. For example, a tuple may be used to
              denote days of a week or months of a year. When the objects within the collection do not appear in any specific order,
              we use the set data type set. A dictionary is used when data is to be stored in the form of key-value pairs. For example,
              in a phone dictionary, each word is associated with one or more meanings. word: meaning may be thought of as a key:
              value pair, where a word is a key associated with a list of meanings of that word.


                       State whether the following are mutable or immutable.

                       1.  marks = 78.50
                       2.  rating = "5 stars"
                       3.  marks = [45,70,65,53]
                       4.  riverNames = ('Ganga','Yamuna','Chenab')
                       5.  rankings = {'points':12, 'rank':2}



              7.5 Operators

              An operator is used to perform a specific operation on an object or objects, also known as operands. For example, in the
              expression 10 + 20, the values 10 and 20 are operands, and + is an operator. Python's operators can be grouped
              into two main groups based on how many operands they work with. A unary operator takes only one operand, while
              a binary operator takes two operands. For example, the unary minus (-) and unary (+) are used to specify positive or
              negative signs of a number. However, the binary arithmetic operators, such as + (addition),- (subtraction),*(product),
              and / (division) need two operands. Consider the following statement:

              value = –6 + 9.2
              In the expression on the RHS, the first operator (unary minus) is a unary operator, and the second operator (+) is a
              binary operator that will perform the addition of the operands -6 and 9.2. Therefore, the final value 3.2 will be
              assigned to the variable value.

               162   Touchpad Computer Science (Ver. 2.0)-XI
   171   172   173   174   175   176   177   178   179   180   181