Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 138 - CodePilot V5.0 C6
P. 138

    DECLARING AND INITIALISING A VARIABLE
                      In Python, you can declare and initialise a variable in one step. For example:

                      x = 5
                      y = 10
                      print("x =", x)
                      print("y =", y)
                      In  this  example,  the  variables  x and y are initialised  with the values 5 and 10, respectively.
                      The output will be:

                      x = 5
                      y = 10
                      You can also assign the same value to multiple variables in a single line:

                      a = b = 30
                      print("a =", a)
                      print("b =", b)
                      In this case, both a and b will store the value 30 and the output will be:

                      a = 30
                      b = 30
                      Additionally, you can assign multiple values to multiple variables in a single line. For example:

                      name, age, city = "John", 25, "London"
                      print("Name:", name)
                      print("Age:", age)
                      print("City:", city)
                      The output will be:

                      Name: John
                      Age: 25
                      City: London

                             DATA TYPES

                      A data type defines the kind of value a variable can hold and the operations allowed on it.
                      For example, names are strings (text) and can be changed to uppercase or lowercase, while age,
                      price and marks are numbers, either integers or floats and can be used in calculations.

                      Let’s look at some commonly used data types in Python:
                          int: It represents positive or negative whole numbers (without fractions).

                         For example:
                         a = 9

                       136
                            CodePilot (V5.0)-VI

         5

| 133 134 135 136 137 138 139 140 141 142 143 |