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

Table 6.3 shows some of the commonly used operators in Python. You will learn about operators in detail in the next
              chapter.
                                                      Table 6.3: Operators in Python
                                     +  -   *   /   %   //  **          Arithmetic Operators

                                     =                                  Assignment operator
                                     ==, !=, >, <, >=, <=               Relational Operators
                                     and, or, not                       Logical Operators

              6.3 Variables

              A variable (also called a name) is an identifier that denotes a data value. For example, using the assignment operator
              (=), the data values 'India' and 225.6 may be associated with the variables country and area, respectively,
              as follows:
               >>> country = 'India'
               >>> area = 225.6
              Python syntax for assigning a value to a variable may be described as follows:
              Syntax:

              <Variable_name> = <value>
              In this book, we use the above notation to describe Python syntax. While the text in the angular brackets is replaced
              by the appropriate Python expressions, the keywords and the operators appear as they are. Thus, in the assignment
              statement,

              country = 'India'
              Variable_name is replaced by the variable name country, the assignment operator = appears as described in
              the syntax, and value is replaced by the value 'India'.



                                                   country                  India





                                                    area                  3287000


              Now, let us have a look at some examples of valid and invalid variable names.

                  Examples of Valid Identifiers      Examples of Invalid Identifiers

                  Roll_no                            My name                           (Space included)
                  rollNo                             1day                                  (Starts with a digit)
                  _num                               Come#go                          (Contains a special character, #)
                  WHILE                              max-marks                       (Contains a special character, - (hyphen))
                  price



                       Which of the following identifiers are valid/invalid?
                          #metoo, _dayName, print, add&subtract, first name, currenyIn$


              In Python, the type of a variable is not declared explicitly. Instead, a variable gets associated with a type that is
              determined implicitly from the context.

               130   Touchpad Computer Science (Ver. 2.0)-XI
   139   140   141   142   143   144   145   146   147   148   149