Python Data Types

Python Data Types

Gopika M


Python Data Types

In programming, a data type defines the kind of value a variable can store and the operations

that can be performed on it. Python is dynamically typed, meaning you don’t need to declare a

data type explicitly—Python determines it automatically based on the value assigned.

Different data types serve different purposes, such as storing text, numbers, collections, or

logical values.

Built-in Data Types in Python

Python provides several built-in data types, grouped into the following categories:

  •  Text Type: str
  •  Numeric Types: int, float, complex
  •  Sequence Types: list, tuple, range
  •  Mapping Type: dict
  •  Set Types: set, frozenset
  •  Boolean Type: bool
  •  Binary Types: bytes, bytearray, memoryview
  •  None Type: NoneType


Checking the Data Type

You can identify the data type of any variable or object using the built-in type() function.

Example:

Try it Yourself

Data Types Are Assigned Automatically

In Python, the data type is assigned at the moment a value is stored in a variable.

Examples:

Try it Yourself

Explicitly Setting a Data Type

If you want to control or convert the data type explicitly, Python provides constructor functions

for each type.

Examples:

Try it Yourself

Constructor functions are especially useful when working with user input, file data, or type conversions.

Our website uses cookies to enhance your experience. Learn More
Accept !