data-types.org
changeset 94 57ae1f75b7e0
parent 92 fa26bdda8f32
equal deleted inserted replaced
93:bdee3ead116d 94:57ae1f75b7e0
     8 *** Script
     8 *** Script
     9     Welcome friends. 
     9     Welcome friends. 
    10     
    10     
    11     In this tutorial we shall look at data types available in Python and 
    11     In this tutorial we shall look at data types available in Python and 
    12     how to perform simple Input and Output operations. 
    12     how to perform simple Input and Output operations. 
    13     for dealing with 'Numbers' we have: int, float, complex
    13     for 'Numbers' we have: int, float, complex datatypes
    14     'Strings' are there for handling Text content.
    14     for Text content we have strings.
    15     For conditional statements 'Booleans' are supported.
    15     For conditional statements, 'Booleans'.
    16     
    16     
    17     Lets start by covering one by one, firstly 'numbers'
    17     Lets get started by opening IPython interpreter. 
    18     All integer numbers irrespective of how big they are, are of 'int'
    18     Lets start with  'numbers'
       
    19     All integers irrespective of how big they are, are of 'int'
    19     data type
    20     data type
    20     Lets get started by opening IPython interpreter. Now we will create
    21     Now we will create a variable, say
    21     some variables say:
    22     x = 13
    22     a = 13
    23     print x
    23     print a
       
    24 
    24 
    25     To check the data type of any variable Python provides 'type' function
    25     To check the data type of any variable Python provides 'type' function
    26     type(a)
    26     type(x)
    27     
    27     
    28     b = 999999999999
    28     y = 999999999999
    29     print b
    29     print y
    30     
    30     
    31     Floating point numbers comes under 'float'
    31     Floating point numbers comes under 'float'
    32     p = 3.141592
    32     p = 3.141592
    33     type(p)
    33     type(p)
    34 
    34 
    35     Python by default provides support to complex numbers. 
    35     Python by default provides support for complex numbers. 
    36     c = 3+4j 
    36     c = 3+4j 
    37     c is a complex number. 'j' is used to specify the imaginary part.
    37     c is a complex number. 'j' is used to specify the imaginary part.
    38     type(c)
    38     type(c)
    39     Python also provides basic functions for their manipulations like
    39     Python also provides basic functions for their manipulations like
    40     abs(c) will return the absolute value of c(sqrt(a^2 + b^2))
    40     abs(c) will return the absolute value of c(sqrt(a^2 + b^2))
    41     c.imag returns imaginary part of the variable
    41     c.imag returns imaginary part and c.real gives the real part. 
    42     and similarly c.real gives real part.
       
    43 
    42 
    44     Next we will look at Boolean data types:
    43     Next we will look at Boolean datatype:
    45     Its a primitive datatype having one of two values: True or False.
    44     Its a primitive datatype having one of two values: True or False.
    46     t = True
    45     t = True
    47     print t
    46     print t
    48 
    47 
    49     Python is case sensitive language, so True with 'T' is boolean type but
    48     Python is case sensitive language, so True with 'T' is boolean type but
    97     Some of methods available for string are:
    96     Some of methods available for string are:
    98     a.startswith('Thi')
    97     a.startswith('Thi')
    99     returns true if initial of the string is same
    98     returns true if initial of the string is same
   100     similarly there is endswith
    99     similarly there is endswith
   101     a.endswith('ING')
   100     a.endswith('ING')
   102     a.upper() returns a string will all letters capitalized.
   101     a.upper() returns a string with all letters capitalized.
   103     and a.lower() returns a string with all smaller case letters.
   102     and a.lower() returns a string with all smaller case letters.
   104     As we have seen earlier use of split function, it returns the list after
   103     As we have seen earlier use of split function, it returns the list after
   105     splitting the string, so
   104     splitting the string, so
   106     a.split()
   105     a.split()
   107     will give list with three elements.
   106     will give list with three elements.
   108     Opposite to this function, we also have 'join' function.
   107     we also have 'join' function, which does the opposite of what
       
   108     split does. 
   109     ''.join(['a','b','c']) will return a joined string of the list we pass
   109     ''.join(['a','b','c']) will return a joined string of the list we pass
   110     to it. Since join is performed on '' that is empty string we get 'abc'
   110     to it. Since join is performed on '' that is empty string we get 'abc'
   111     if we do something like
   111     if we do something like
   112     '-'.join(['a','b','c'])
   112     '-'.join(['a','b','c'])
   113     
   113     
   114     Thus we come to the end of this tutorial on introduction of Data types in
   114     we come to the end of this tutorial on introduction of Data types in
   115     Python. In this tutorial we have learnt what are supported data types, 
   115     Python. In this tutorial we have learnt what are supported data types, 
   116     supported operations and performing simple IO operations in Python.
   116     supported operations and performing simple IO operations in Python.
   117 
   117 
   118 *** Notes
   118 *** Notes