Basic data types and data structures in python ? [ P – 1]

Home Forums Python Programming Basic data types and data structures in python ? [ P – 1]

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1935 Reply
    Humble
    Keymaster

    Received an email from one of the forum member to write about various python bits in a more concluded way.. so starting with basic data types an will continue…

    Basic data types:
    1) integers
    2) floats
    3) boolean

    No need for explanation on above things, but some examples:

    >>>> x = 5
    >>> type(x)
    <type 'int'>
    >>> x= 5.5
    >>> type(x)
    <type 'float'>
    >>> x = True
    >>> type(x)
    <type 'bool'>
    >>> 
    
    
    Boolean can be one of 'True' or 'False'..
    
    Now, if you want to convert any of these 'basic data types' to another , you could try something like this:
    
    
    >>>> x= 5
    >>> type(x)
    <type 'int'>
    >>> float(x)
    5.0
    >>> type(x)
    <type 'int'>
    >>> x= 9.8
    >>> int(x)
    9
    >>> x=True
    >>> int(x)
    1
    >>> x=False
    >>> int(x)
    0
    >>> float(x)
    0.0
    
    >>> x=True
    >>> float(x)
    1.0
    >>> 
    
    
    
    Basic datatypes can be type casted ( I use this word from C point of view) to any other via above method..
    
    
    Thats it with basic data types.. Shoot your queries here if you would like to know more about these or if you would like to clarify your doubts..
Viewing 1 post (of 1 total)
Reply To: Basic data types and data structures in python ? [ P – 1]
Your information: