Data Types: Python

Continuing with series of Python after Identifier and reserved keywords today we’re going to look into the most important topic “Data Types in Python” I’ll be briefing about all the data types even which are not used mostly but are equally important.

In general Python has 14 Data Types. Since in the first tutorial itself I’ve mentioned we’ll be breaking each topic and deep dive to make our concept clear, Data types will be divided briefly in 4 posts so that we cover all the aspects of it.

We will also consider Data Types with respect to Python2 and Python3 so that you all will be aware which is deprecated and which is being replaced.

  1. intIt is used to represent integral values, In Python2 there was long but from Python3 long can also be used and represented by int.
  2. float
  3. complex10+2j
  4. bool
  5. str
  6. bytes
  7. bytearray
  8. range
  9. list
  10. tuple
  11. set
  12. frozenset
  13. dict
  14. None

Before we deep dive into individual data types, the first and the most important thing to remember is that, In Python everything is Object even methods/function and Datatypes.

Screen Shot 2018-12-01 at 3.15.53 PM

In the above schematic diagram…… a is variable who holds the value 10. As we said even the data types in Python is Object Oriented we should understand the concept as per Object Oriented Programming. Now when we talk about the Object Oriented Programming, a is reference variable who points to a location in memory and that holds the value 10. I know some of the people are confused, but “patience is the key to success”

I’ll be having one separate tutorial in the same series itself regarding the Object Oriented Concepts.

Now as the background is clear let’s deep dive into data types.

1. int: Integer, the number without decimal point i.e. Integral values.

e.g. 10,20,30,10000 etc

>>> a = 10

>>> type(a)

<class ‘int’>

>>> print a


In the first line we have defined an variable of type int a, and assigned value 10. type(a) gives the class of the variable which says int. In the next line we are printing the value of the variable where we’re getting 10.

int can represent value in 4 ways only.

  1. Decimal form – (Base -10) [0-9]
  2. Binary form – (Base -2) [0&1]
  3. Octal form – (Base -8) [0-7]
  4. Hexa Decimal – (Base -16)[0-9] & [a-f] Here Python is case insensitive.

2. float: Number with decimal point, it doesn’t include double values.

e.g Salary:  234556.55, price 233.44

>>> f =123.445

>>> type(f)

<class ‘float’>

Exponential calculation is allowed for floating data types.

In this tutorial we’ve seen two types of Data types in the next consecutive tutorial we will be covering rest of them.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s