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

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.





                                                                                    Basics of Python Programming  125
   122   123   124   125   126   127   128   129   130   131   132