Page 149 - Computer Science Class 11 With Functions
P. 149

Python-Data Types





                            Numeric       Boolean        Sequence Type        Set          None        Dictionary




                  Integer              Complex      Strings             Tuple


                              Float                            List

                                                    Fig 7.1: Data Types in Python

            7.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'>


                                                                                        Data Types and Operators  147
   144   145   146   147   148   149   150   151   152   153   154