Page 167 - Computer Science V2.0 Class 11
P. 167

●  float  (floating  point  numbers):  A  float  data  type  includes  the  floating  point  numbers.  A  floating  point
                   number typically (although not necessarily) includes a decimal point. For example, 10.5, -50.0, 15.908 are
                   floating-point numbers. Next, let us examine a floating point object  fNum,  constructed using a floating point
                   number.
                  >>> fNum = 2 * 3.14 * 5
                  >>> type(fNum)
                      <class 'float'>

                        Python also allows scientific notation to express floating point numbers. In scientific notation, the symbol E denotes
                        base 10 for the exponent, For example,
                        >>> 1.5E2
                            150.0
                                                                      2
                        In the above example, 1.5E2 denotes the number 1.5 × 10 . Next, let us see some more examples,
                        >>> 1E2
                            100.0
                        >>> -2.2E2
                            -220.0
                        >>> -2.2E-2
                            -0.022


                 ●  Complex: A complex number is of the form x + yj and comprises a pair of floating point numbers. The first one
                   (x) is called the real part, and the second one (y) is called the imaginary part. Some examples of complex numbers
                   are 5 + 6j, 3 - 2j, 2 + j and so on. The real and imaginary parts of a complex number can be retrieved
                   as shown below:
                  >>> a = 5 + 6j
                  >>> a
                      (5 + 6j)
                  >>> a.real
                      5.0
                  >>> a.imag
                      6.0
                 Let us now examine the type of a complex object and its parts,
                  >>> type(a)
                      <class 'complex'>
                  >>> type(a.imag)
                      <class 'float'>
                  >>> type(a.real)
                      <class 'float'>
                 Note that when we write a = 5 + 6j, Python interprets 5 and 6 as floating point numbers.



                        In a complex number  of the form of the form x+yj, j denotes  –1.


                 7.1.2 bool (Boolean)

                 In Python, the  Boolean  data type  is called  bool  and  includes  two  values:  True  and  False.  An  expression
                 constructed  using  Boolean  values  is  called  a  Boolean  expression.  Interestingly,  in  a  Boolean  expression,  Python
                 considers the numeric value 0 as False and a numeric value other than 0 as True. Now, let us examine the following
                 examples,
                  >>> condition = True
                  >>> type(condition)
                      <class 'bool'>

                                                                                             Data Types and Operators  153
   162   163   164   165   166   167   168   169   170   171   172