What Are The Common Built-In Data Types In Python?

What Are The Common Built-In Data Types In Python?

Published on October 03 2023

In this tutorial, we will learn about the different data types available in Python and where to use each in detail. This tutorial is part of Python's top 25 most commonly asked interview questions.

Definition

  • There are several built-in data types in Python.
  • Python doesn't require data types to be defined explicitly during variable declarations, but sometimes type errors can occur.
  • Sometimes we use terms like sequence, and numeric types.
  • type() and isinstance() function to check the type of these variables.

Sample Code

a = 5 
print(type(a))
# output
<class 'int'>
a = 5 
print(isinstance(a, int))
# output
True

Types

  • Mutable: can be modified
    • Lists
    • Dictionary
    • Sets
    • User-defined classes (depends upon the user to define the characteristics)
  • Immutable: cannot be modified
    • Numbers (Int, float, bool, etc)
    • Strings
    • Tuples
    • Frozen sets
    • User-defined classes (depends upon the user to define the characteristics)

To know about it, please refer to the official documentation website - official website.