Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Python arithmetic operators

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly talks about "what are the Python arithmetic operators". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what the Python arithmetic operators are.

Python arithmetic operator

Programming languages have corresponding operators, and arithmetic operators are used to perform mathematical operations on numbers, such as addition, subtraction, multiplication and division. The following table shows all the basic arithmetic operators supported by Python.

The operator shows that the result of the example + plus 12.45 + 1527.45-minus 4.56-0.264.3 * times 5 * 3.618.0 / division (as in mathematics) 733.5 stroke / integral division (only keeps the integer part of quotient) 7 / / 23% remainder, that is, returns the remainder of division 7% 21 * exponentiation / power operation, that is, returns x to the power of y 2 * * 416, that is, 24

There is nothing to say about addition, subtraction, multiplication and division, it should be understood, but we should pay attention to the following points!

Note:

When + is used for numbers, it means addition, but when + is used for strings, it also has the function of concatenating strings (concatenating two strings into one).

-in addition to being used as a subtraction operation, it can also be used as a negative operation (a positive number becomes a negative number, a negative number becomes a positive number).

* in addition to being used for multiplication, it can also be used to repeat strings and concatenate n of the same strings.

/ represents ordinary division, and the result calculated by it is the same as that in mathematics.

/ / indicates integral division, keeping only the integer part of the result and discarding the decimal part; note that the decimal part is discarded directly, not rounded.

The divisor can never be 0, and dividing by 0 is meaningless, which results in a ZeroDivisionError error.

The% operator is used to find the remainder of the division of two numbers, including integers and decimals. The essence of the remainder operation is division, so the second number cannot be 0, otherwise it will result in a ZeroDivisionError error.

The result of the remainder is negative only when the second number is negative. Therefore, the positive or negative result of the remainder has nothing to do with the first number, but is only determined by the second number.

When the numbers on both sides are integers, the result of the remainder is also an integer, but as long as one number is a decimal, the result of the remainder is a decimal.

The * * operator is used to find an x to the y power, that is, the power (power) operator. Because the power is the inverse operation of the power, the * operator can also be used to implement the square operation indirectly.

At this point, I believe you have a deeper understanding of "what are the Python arithmetic operators?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report