Python Data Types

A Data type is the type of value a variable can store. Python is dynamically typed programming language, meaning we do not need to declare data type of a variable. However, you must know what data types are supported in Python. Python supports the following data types by default:

Data Type Description Example
str A string which is a sequence of character. x = "Hello World"
int Numeric value without decimal point. a = 467
float Numeric value with decimal point. 14.7
complex Numeric real value with imaginary component. x = 14j
list Collection of ordered and mutable data. This type allows duplicate values. x = ["apple", "grapes", "mango", "orange", "apple"]
tuple Collection of ordered and immutable data. This type allows duplicate values. x = ("apple", "grapes", "mango", "orange", "mango")
dict A collection with key-value pairs which are unordered, unindexed and mutable. This type allows no duplicate keys. {` a = {"name" : "Danny", "email" : "danny@tutorialsbuddy.com"}`}
set A collection with unindexed and unordered values. This type allows no duplicate values. a = {`{"pen", "book", "laptop"}`}
frozenset A built-in function to make iterable object immutable. forzenset({`{"pen", "book", "laptop"}`})
bytes A byte representation of an object value. a = b"Hello World"
bytearray A built-in function to convert object's value into bytearray. x = bytearray(10)
memoryview A built-in function to convert object into memoryview object. Memoryview allows to safely access the internal buffer of an object in Python. Internal buffer refers to a physical memory storage used temporarily to store data. x = memoryview(bytes(10))
bool A boolean value either True or False. x = True
range A built-in function that generates a sequence of numbers starting with 0 by default and stops just before the specified number. It is commonly used in for loop. for i in range(10):
print(i, end = " ")
print()

How to find data type of an object or a variable?

To find the data type of an object or a variable, you can simply use the type() function of Python.

Example

x = 67
print(type(x))
  
Output
<class 'int'>