Page 431 - AI Ver 3.0 class 10_Flipbook
P. 431

Unlike other programming languages, variables in Python are not created before. They are created automatically
                 when a value is assigned to it using the assignment operator (=) Value to be assigned is always on the right side
                 of the equal to. A variable assigned with a value of one type can be re-assigned a new value of a different type as
                 shown below:

                 [1]:   a=9
                        print(a)
                        a="Orange"
                        print(a)

                        9
                        Orange

                 There are different ways of assigning values to different variables in Python:

                    • Method 1: Assigning different values to different variable in different lines.

                 [1]:   rollno = 5
                        strength = 10.5
                        name = "Amita"

                    • Method 2: Assigning different values to different variable in the same line.

                 [1]:   rollno, strength, name = 5, 10.5, "Amita"


                    • Method 3: Assigning same values to different variables in the same line.

                 [1]:   marks1 = marks2 = marks3 = 45

                 Data Types


                 Data types specify the kind of a value a variable can store. It helps us to identify the kind of operation that can
                 be performed on that specific data type. Every value in Python has a data type.

                                                                Data Types




                                   Numbers          None          Boolean      Sequences      Sets     Maps






                             int      float     complex              string     list      tuple      Dictionary

                 The description of these data types is as follows:
                    • Numbers: Data with a numeric value fall into this category. It can be integer, float or complex. Python will
                   automatically convert a number from one type to another if needed. Following are the number datatype.
                       ✶ Integer: Integers are whole numbers (+ve, -ve or 0) with no fractions or decimal value. Range of an integer in
                      Python can be from -2147483648 to 2147483647, and long integer has unlimited range subject to available
                      memory. For example, 10, 124, –4567, 7812568751.

                       ✶ Float: It is a real number with floating point representation. For example, 5.0, 15.5 or -12.7. It can also be
                      represented using the exponent notation E. For example, 1E5 is 100000.
                       ✶ Complex: It is made up of a real number and an imaginary number. For example, 3+2j where 3 is a real
                      number, 2 is an imaginary number, and j is the imaginary unit.
                                                                                    Advance Python (Practical)  429
   426   427   428   429   430   431   432   433   434   435   436