Python Data Types

About Python Data Types

In Python, a data type specifies which type of value a variable can hold.

Python is dynamically typed language. The interpreter automatically determines the data type based on the value assigned to the variable.

Understanding data types is crucial in programming. It is essential to be aware of the data types to write correct and efficient code.

Built-in Data Types in Python

The following are the fundamental data types in Python:

Numeric Types

int: Integer type represents whole numbers.

Example of Integer Type:

float: Float type represents floating-point numbers.

Example of Float Type:

complex: Complex type represents complex numbers with a real part and imaginary part.

Example of Complex Type:

Sequence Types:

str: String type represents sequences of characters.

Example of String Type:

list: List is an ordered and mutable sequence of elements.

Example of List Type:

tuple:: Tuple is an ordered and immutable sequence of elements.

Example of Tuple Type:

Set Types

set: Set is an unordered collection of unique elements.

Example of Set Type:

frozenset: Frozenset is an immutable set.

Example of Frozenset Type:

Mapping Type

dict: Dictionary is an unordered collection of key-value pairs.

Example of Dictionary Type:

Boolean Type

bool: Boolean type represents either True or False.

Example of Boolean Type:

None Type

NoneType: The special type None represents a null value.

Example of None Type:

Binary Types:

bytes: Immutable (cannot be changed) sequence of bytes.

Example of Bytes Type:

bytearray: Mutable (can be changed) sequence of bytes.

Example of Bytearray Type:

memoryview: A view object that exposes an array’s buffer interface.

Example of Memoryview Type:

Python Compiler For Live Practice

Practice the above Python code in the following Python Editor. Create more Python variables of different data types in the following code editor and click Execute button. Output will be displayed in Python Code Output section.

Python logo Python Editor
Python Code Output