Page 439 - ComputerScience_Class_11
P. 439

Output

                  floating value 4.6
                  1.1





                       Note: Float can also be scientific numbers with an "e" to indicate the power of 10.


                 12.2.3 Complex
                 A complex number is a numeric data type in Python that represents numbers in the form a + bj, where a is the real
                 part, b is the imaginary part and j (or J) represents the imaginary unit equal to the square root of -1 (√-1). It is used
                 for advanced mathematical, scientific, engineering and graphical computations.
                 Syntax of complex is as follows:

                 variable_name = real_part + imaginary_partj
                 Program 3: To display a complex number in Python.
                     Program 3.py

                  File  Edit  Format   Run   Options   Window     Help

                  # Assign a complex value to a variable
                  x = 3 + 4j
                  # display the value of x
                  print("Complex value: ", x)
                  # Assigning another complex number to variable
                  y = 5 + 3j
                  # Display the value of y
                  print("Complex value: ", y)




                     Output

                  Complex value:  (3+4j)
                  Complex value:  (5+3j)




                 12.2.4 Characteristics of Numeric data types in Python
                 There are some characteristics of numeric data types in Python:
                 •  Support Type Conversion: Numeric values can be converted from one type to another using functions like int(),
                   float() and complex().
                 •  Used in Mathematical Calculations: Numeric data types are mainly used to perform calculations in programs.
                 •  Do Not Store Multiple Values: A numeric variable stores only a single number at a time.
                 •  Can Be Used in Conditions: Numeric values can be used in if statements and other logical conditions.
                 •  Stored in Memory as Objects: Even numbers are treated as objects in Python.

                       Note: Numeric type conversion in Python changes a number from one type to another using built-in
                       functions; int() for integers, float() for decimals and complex() for complex numbers.




                                                                                               Data Types in Python  437
   434   435   436   437   438   439   440   441   442   443   444