What are Data Types in Python? (With Complete List)

What are Data Types in Python


Python is a dynamically typed language, which means variables are not explicitly declared with a data type. Instead, the data type is inferred based on the value assigned to the variable. Python provides several built-in data types in Python to represent different kinds of values. Here's a complete guide to the commonly used data types in Python:

Numeric Types:

int: Represents integer values, such as 3, -5, or 0.

float: Represents floating-point values with decimal points, such as 3.14 or -2.5.

complex: Represents complex numbers in the form a + bj, where a and b are floats, and j represents the imaginary unit.

Sequence Types:

str: Represents a sequence of Unicode characters, such as "hello" or 'world'.

list: Represents an ordered collection of elements enclosed in square brackets and separated by commas, such as [1, 2, 3] or ['apple', 'banana'].

tuple: Represents an ordered, immutable collection of elements enclosed in parentheses and separated by commas, such as (1, 2, 3) or ('a', 'b').

Mapping Type:

dict: Represents a collection of key-value pairs enclosed in curly braces, where each key is unique and associated with a value, such as {'name': 'John', 'age': 25}.

Also read: Is Python the Easiest Programming Language?

Set Types:

set: Represents an unordered collection of unique elements enclosed in curly braces or created using the set() constructor, such as {1, 2, 3} or set([1, 2, 3]).

frozenset: Represents an immutable version of a set, created using the frozenset() constructor.

Boolean Type:

bool: Represents a Boolean value, which can be either True or False. Often used in logical expressions and control flow.

Also read: Why Python is Interpreted Language?

None Type:

None: Represents the absence of a value. Used to indicate the absence of a meaningful result or when a variable doesn't have a value assigned.

Other Types:

bytes: Represents a sequence of bytes. Often used to handle binary data or interact with binary files.

bytearray: Similar to bytes, but mutable.

range: Represents an immutable sequence of numbers generated by the range() function.

enum: Represents a set of named values.

These data types provide the foundation for storing and manipulating different kinds of data in Python. Additionally, Python also allows you to define and use custom data types using classes and objects, providing flexibility and extensibility to the language. If want to learn Python free then visit Tutorials Freak for Free Python Tutorial for beginners.

Post a Comment

Previous Post Next Post