Python Data Types
Data Types
For short, a data type describes a set of possible values and operations that can be performed on a variable
In Python, a data type is a category for values. Every value in Python has a data type, which determines the kind of operations that can be performed on that value and the way the value can be stored in memory.
There are several built-in data types in Python, including:
Numbers: Python has three types of numbers: integers (int), floating-point numbers (float), and complex numbers (complex). Integers are whole numbers, while floating-point numbers have decimal points. Complex numbers have a real and imaginary part.
Strings: A string is a sequence of characters, represented by either single quotes (') or double quotes ("). Strings can contain letters, numbers, and special characters.
Lists: A list is an ordered collection of values that can be of any data type. Lists are written as a series of values separated by commas and enclosed in square brackets.
Tuples: A tuple is similar to a list, but it is immutable, meaning that its values cannot be modified once it is created. Tuples are written as a series of values separated by commas and enclosed in parentheses.
Sets: A set is an unordered collection of unique values. Sets are written as a series of values separated by commas and enclosed in curly braces.
Dictionaries: A dictionary is a collection of key-value pairs. The keys must be unique and are used to retrieve the corresponding values. Dictionaries are written as a series of key-value pairs separated by commas and enclosed in curly braces.
In addition to these built-in data types, you can also define your own data types in Python using classes (more of this in an advanced topic)
Last updated