+ INFORMATION

Share on social networks!

Python data types

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.

Image

Chains

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.

Image

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.

Image

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.

Image


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.

Image

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.

Image

¡Discover our Master in Advanced Programming in Python for Big Data, Hacking and Machine Learning!

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SA as the person responsible for this website. The purpose of collecting and processing personal data is to respond to the query made as well as to send information about the services of the data controller. Legitimation is the consent of the interested party.
You can exercise your rights of access, rectification, limitation and deletion of data in compliance@grupomainjobs.com as well as the right to file a claim with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find in our Web page
marter-in-python

Leave a comment