What are python data types

  • Data Type represents the type of data present inside a variable. 
  • In Python, we are not required to specify the type explicitly. Based on the value provided, the type will be assigned automatically. Hence Python is a Dynamically Typed Language.
  1. Boolean:  The type of the built-in values True and False. Useful in conditional expressions, and anywhere else you want to represent the truth or falsity of some condition. Mostly interchangeable with the integers 1 and 0. In fact, conditional expressions will accept values of any type, treating special ones like boolean False, integer 0 and the empty string "" as equivalent to False, and all other values as equivalent to True. But for safety’s sake, it is best to only use boolean values in these places.
  2. Numeric types:

    • int: Integers; equivalent to C longs in Python 2.x, non-limited length in Python 3.x
    • long: Long integers of non-limited length; exists only in Python 2.x
    • float: Floating-Point numbers, equivalent to C doubles
    • complex: Complex Numbers

  3. Sequences:

    • str: String; represented as a sequence of 8-bit characters in Python 2.x, but as a sequence of Unicode characters (in the range of U+0000 - U+10FFFF) in Python 3.x
    • bytes: a sequence of integers in the range of 0-255; only available in Python 3.x
    • byte array: like bytes, but mutable (see below); only available in Python 3.x
    • list
    • tuple

    Sets:

    • set: an unordered collection of unique objects; available as a standard type since Python 2.6
    • frozen set: like set, but immutable (see below); available as a standard type since Python 2.6

  4. Mappings:

    • dict: Python dictionaries, also called hashmaps or associative arrays, which means that an element of the list is associated with a definition,

Note: Python contains several inbuilt functions

1) type() : to check the type of variable.
  1. a = ('Python', 'Data', 'Type')
  2. b = "Tipszon"
  3. c = 33
  4. x = type(a)
  5. y = type(b)
  6. z = type(c)
  7. print(x)
  8. print(y)
  9. print(z)
Output
  1. <class 'tuple'>
  2. <class 'str'>
  3. <class 'int'>

 2) id() : to get address of object

  1. x = ('Python', 'Data', 'Type')
  2. y = id(x)
  3. print(y)
Output
  • 74768637

3) print() : to print the value