Page 82 - Information_Practice_Fliipbook_Class11
P. 82

4.1.1 Numeric

        The numeric data types deal with numbers or numeric values. We can perform arithmetic operations on numeric types
        of data. The numeric types include integers, floating point numbers, and complex numbers:
        ●  int (integer):  The  data  type  int includes  integers.  Literals  of  type  int  may  be  positive,  negative,  or  zero.
           For example, 1,-29,78, and 0 are values of the int data type. Interestingly, Python does not allow leading
           zeros. For example,
         >>> 07
              SyntaxError: leading zeros in decimal integer literals
              are not permitted; use an 0o prefix for octal integers
        However, Python does allow the use of octal and hexadecimal integers. An octal integer begins with 0o, followed by
        a sequence of digits. For example,

         >>> 0o234
              156
         >>> 0o1000
              512
         >>> -0o234
              -156
         >>> -(0o234)
              -156
        A hexadecimal integer begins with 0x, followed by a sequence of digits. For example,
         >>> 0x23
              35
         >>> -0x128
              -296
        type()

        The function type() returns the type of an object.

        Syntax
          type(<name> | <value>)
        Note that in the above description, a vertical bar denotes an option. Thus, we may like to fetch the type of object that
        a name refers to, or we may specify the object directly. For example,

         >>> type(123)
              <class 'int'>
         >>> type(0x123)
              <class 'int'>
         >>> num = -56
         >>> type(num)
              <class 'int'>
        ●  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. Now, let us compute the circumference of a circle with a radius (r) of five.

        We set the radius (r) of the circle to 5 and use the formula to compute the circumference of a circle (2 * π * radius).
        It is to note that the floating point object 3.14, denoting the value of  pi (π)is multiplied by the objects of int type.
        As a consequence, circumference is also an object of floating point type.
         >>> r = 5
         >>> circumference = 2*3.14*r
         >>> type(circumference)
              <class 'float'>






          68   Touchpad Informatics Practices-XI
   77   78   79   80   81   82   83   84   85   86   87