top of page

Python Data Types

Python Support different types of  built-in data types, which is given below –

Here below the list of built-in data types categories 

  • Numeric Types: int, float, complex

  • Text Type: str

  • Sequence Types: list, tuple, range

  • Mapping Type: dict

  • Set Types: set, frozenset

  • Boolean Type: bool

  • Binary Types: bytes, bytearray, memoryview

 

How we can find data type

 

The data type can be found using type() keyword.

>>>a=5

>>>print(type(a))

It gives the result “int” data type.

Python Numbers

# creating int data type

x = 5

print("Value of X =", x,  "and type of x is", type(x))

# creating float data type

x = 5.0

print("Value of X =", x,  "and type of x is", type(x))

# creating int data type

x = 5 + 4j

print("Value of X =", x,  "and type of x is", type(x))

Python String

String is sequence of Unicode characters.

 

We can assign string value to a variable with  single quotes or double quotes.

 

Multi-line strings can be denoted using triple quotes, ''' or """.

# Assigning string value   with single quote

company_name = 'Codersarts.com'

print("Value of company_name =", company_name,  "and type of company_name is", type(company_name))

# Assigning string value with double quote

company_name = "Codersarts.com"

print("Value of company_name =", company_name,  "and type of company_name is", type(company_name))

# multi line string

x = """ We can assign string value to a variable with  single quotes or double quotes.

Multi-line strings can be denoted using triple quotes.

"""

print("Value of X =", x,  "and type of x is", type(x))

Others data types

x = ["apple", "banana", "cherry"]                                   #list

x = ("apple", "banana", "cherry")                                   #tuple

x = range(6)                                                                        #range

x = {"name" : "John", "age" : 36}                                   #dict

x = {"apple", "banana", "cherry"}                                   #set

x = frozenset({"apple", "banana", "cherry"})                  #frozenset

x = True                                                                               #bool

x = b"Hello"                                                                       #bytes

x = bytearray(5)                                                                  #bytearray

x = memoryview(bytes(5))                                                 #memoryview

In the next tutorial, we will learn about “python numbers

bottom of page