Techno Blender
Digitally Yours.

Understanding Operators in Python | by Niklas Lang | Nov, 2022

0 30


Get to know the fundamentals of Python Operators

Photo by Dan Lohmar on Unsplash

Python operators are special types of functions that perform certain, mostly mathematical, operations in the Python programming language.

In Python, there are the so-called operators, which, like a function, execute fixed-defined actions. However, a function does not have to be defined in a conventional way, but much shorter operators can be used. Python operators are already installed in the basic version of Python and do not have to be added by importing an additional module.

More generally, a Python operator consists of the left side, the operator, and the right side. The operator determines what happens to the right and left sides. Depending on the source, this is also referred to as the operands. We will use this term in this article.

There are countless operators in Python which we will discuss further in the following chapters. One of them is the mathematical difference, which can be called using the character “-“.

In our example, the minus sign is the operator. The two operands are the numbers nine and three. Finally, the number six is the result of the operation.

Python distinguishes between different types of operators, which we will explain in more detail in the following chapters.

Comparison Operators

The comparison operators can compare two operands with each other. They always return a Boolean value (True or False) as the result.

Comparison Operators in Python | Source: Author

Arithmetic / Mathematical Operators

The mathematical or arithmetic operators implement basic mathematical functions in Python. For this, the basic calculation types, such as sum, difference, multiplication, etc. are covered.

Mathematical Operators in Python | Source: Author

Logical Operators

The logical operators are also from mathematics and enable the connection of conditions with the help of the logical And and Or. Two statements linked with “or” are true exactly when one of the two statements is true. Two statements linked with “and” are true exactly when both statements are true.

Logical Operators in Python | Source: Author

Identity Operator

The Python operator “is” is used to check whether two variables have the same value assigned to them. The operator then returns True or False accordingly. This can also be used to check dynamically in a script whether the variables are identical.

Subset Operator

The subset operators can be used to check whether one or more elements are present in a set, such as a Python List.

The negation can be used to check the opposite, i.e. whether the element is not part of the set.

Assignment Operators

We already know the most basic assignment operator from the definition of a variable. With the help of the “=” we can assign a value to a variable. In addition, there are other assignment operators with the help of which, for example, sums or products can be written in a shortened form.

  • Python operators are special types of functions that mostly perform mathematical functions.
  • Python operators allow quick invocation without the need to define a new function.
  • There are different types, such as logical operators or assignment operators.


Get to know the fundamentals of Python Operators

Photo by Dan Lohmar on Unsplash

Python operators are special types of functions that perform certain, mostly mathematical, operations in the Python programming language.

In Python, there are the so-called operators, which, like a function, execute fixed-defined actions. However, a function does not have to be defined in a conventional way, but much shorter operators can be used. Python operators are already installed in the basic version of Python and do not have to be added by importing an additional module.

More generally, a Python operator consists of the left side, the operator, and the right side. The operator determines what happens to the right and left sides. Depending on the source, this is also referred to as the operands. We will use this term in this article.

There are countless operators in Python which we will discuss further in the following chapters. One of them is the mathematical difference, which can be called using the character “-“.

In our example, the minus sign is the operator. The two operands are the numbers nine and three. Finally, the number six is the result of the operation.

Python distinguishes between different types of operators, which we will explain in more detail in the following chapters.

Comparison Operators

The comparison operators can compare two operands with each other. They always return a Boolean value (True or False) as the result.

Comparison Operators in Python | Source: Author

Arithmetic / Mathematical Operators

The mathematical or arithmetic operators implement basic mathematical functions in Python. For this, the basic calculation types, such as sum, difference, multiplication, etc. are covered.

Mathematical Operators in Python | Source: Author

Logical Operators

The logical operators are also from mathematics and enable the connection of conditions with the help of the logical And and Or. Two statements linked with “or” are true exactly when one of the two statements is true. Two statements linked with “and” are true exactly when both statements are true.

Logical Operators in Python | Source: Author

Identity Operator

The Python operator “is” is used to check whether two variables have the same value assigned to them. The operator then returns True or False accordingly. This can also be used to check dynamically in a script whether the variables are identical.

Subset Operator

The subset operators can be used to check whether one or more elements are present in a set, such as a Python List.

The negation can be used to check the opposite, i.e. whether the element is not part of the set.

Assignment Operators

We already know the most basic assignment operator from the definition of a variable. With the help of the “=” we can assign a value to a variable. In addition, there are other assignment operators with the help of which, for example, sums or products can be written in a shortened form.

  • Python operators are special types of functions that mostly perform mathematical functions.
  • Python operators allow quick invocation without the need to define a new function.
  • There are different types, such as logical operators or assignment operators.

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment