Python Data Types

In the last article, we discussed variables, and how to use them. Knowing about data type is important before you start operating with data.

It helps us understand which in-built method and operator can be applied if we know about the data type.

In this article, we’ll discuss the in-built data type in Python.

Boolean Type

  • bool

a = True

Numeric Types

  • int

  • float

  • complex

num_of_students = 10

width = 144.23

ent1 = 2+3j

ent2 = complex(1,4)

Sequence types

  • list

  • tuple

  • range


first_ten_prime_nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

position = (10,10)

span = range(1,100)

Text sequence type

  • str

message = "Hello World of Data Type!!"

Binary sequence type

  • bytes

  • bytearray

  • memoryview

bytes_example = b'example'

bytearray_example = bytearray('example')

Set types

  • set

  • frozenset

dice_outcomes = {1,2,3,4,5,6}

outcomes = frozenset(dice_outcomes)

Mapping types

  • dict

state_capital = {"UP":"Lucknow","Bihar":"Patna"}

We’ll discuss each of these data type in detail in further articles.

If you want to find the type of current object you can use the in-built type function. In the Hello World program, we print the message- Hello World, surrounded by quotes. Let's see what is its type -

type("Hello World")
# <class 'str'>

You can see, already used an object of str datatype without even knowing it. That’s the beauty of dynamically typed language.

Happy Coding. Never Stop Hacking!