Python data types are nothing more than a classification of similar data values. In Python, we do not explicitly declare the data type of a variable. The Python interpreter interprets a value and then automatically assigns it to the appropriate data type
Let's start...
Numbers
In Python, there is a Number data type for all operations involving numeric values. This data type can handle all types of numerical values: integers, floating point numbers, and complex numbers.
Numbers are mutable data types, which means that every time we update a variable, a new object with the updated value is created and assigned to the variable.
Numbers are divided into three Python data types:
- int / Integer: Int can store all integer values. This type of data can be of any size. There is no size limit.
- float: he floating includes all floating point values. There are also no restrictions on the size of a floating point number.
complex– As the name suggests, Python stores numbers in complex form. For example, x + yj, where x is the real part and y is the imaginary part.
Chains
A python string It is nothing but a sequence of characters and is therefore also called a character string.
Strings in Python are immutable; the same String instance cannot be modified. Instead, to update the string value, a new updated instance must be provided.
In Python, we declare strings with a sequence of characters between (“” or “” or “””). For example: “Python”, “Let's go”, “'This is “Python”.'”.
Additionally, we can use the + operator to concatenate two strings.
Booleans
Boolean values in Python include two possible values: True and False
These values are usually used in conditional statements. These two values can be used as operands for logical operations like and , or , not , etc.
Dictionary
Dictionaries are used to store key-value pairs. He python dictionary is an ordered collection of data values; However, we can also retrieve the elements in the order in which we inserted them. A dictionary is mutable, which means that we can edit the elements of a dictionary.
The keys in the dictionary must be unique. The key can be any data type as long as the data type is hashable and immutable. The values can be of any data type and can also be modified. We use {} square brackets or the dict() method to create an empty dictionary.
Lists and tuples
Lists and tuples are used to store a sequence of different types of data.
Lists are addressed with [], while tuples are addressed with (). Python List is mutable while the tuples They are immutable. Both lists can be accessed through an index.
Lists, once created, can be modified, while tuples cannot be modified. If we try to change a tuple, the Python interpreter throws an error.
Sets
Sets are collections messy of unique data values. Data values can be of any data type as long as be hashable and immutable.
Sets can be initialized with data values separated by a comma and enclosed in braces {}.
Sets ignore all repeating values and only store unique elements. The sets are mutable, allowing data values to be updated.
¡Discover our Master in Advanced Programming in Python for Big Data, Hacking and Machine Learning!