Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 142 - 2612 Digimind C6
P. 142

    On the output screen, a = 10 and b = 20 will be printed. You can also assign the same value
                      to multiple variables at the same time in the following way:

                      a = b = 20
                      print ("a=", a)

                      print ("b=", b)
                      On the output screen, a = 20 and b = 20 will be printed.

                      You can also assign multiple values to multiple variables in the same line in the following way:

                      name, age, Class= "Anaya", 12, 'VII'
                      print ("Name is", name)

                      print ("Age is", age)
                      print ("Grade is", Class)
                      On the output screen, Name is Anaya, Age is 12 and Grade is VII will be printed in
                      three lines.

                      You must follow the given rules while creating and naming the variables:

                         A variable name must start with a letter or underscore character.
                         A variable name cannot start with a number.

                          A variable name can only contain alphanumeric characters (all the letters of the alphabet and
                        numbers) and underscores (_).
                         Variable names are case-sensitive.

                         Variable names cannot contain any special character or symbol.

                                COMMENTS IN PYTHON

                      Comments in Python can be used to explain parts of the code. It can also be used to hide the code
                      as well. Python does not execute comments.

                      Comments are not a part of the program, but they do enhance the interactivity of the program
                      and make them readable. Python supports two types of comments: Single-line-comments and
                      multiline comments.
                      Single-line Comment
                      Python uses the hash (#) symbol for writing single-line comments.

                      Example:
                      Program:  #printing a string

                                 print("Hello TrackPad")
                      Output: Hello TrackPad
                      Multiple-line Comment

                      Python does not have a syntax for multiline comments. To add a multiple-line comment, you
                      could insert a # for each line.

                      140   Premium Edition-VI

| 137 138 139 140 141 142 143 144 145 146 147 |