Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the rules of operation between different types of Python

Shulou Source: shulou.com Published: 2022-06-02 12:44:58 10月04日 Update

This article mainly explains "what are the operation rules between different types of Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the operation rules between different types of Python".

Operation rules between different types

Generally speaking, we don't operate on data of numeric type and Boolean type, nor do we operate on data of string type and Boolean type.

We need to use the arithmetic operator provided by Python to complete the operation between variables. Python provides two kinds: arithmetic operator and compound assignment operator.

The arithmetic operator operator describes the example + plus 10 + 20 = 30-minus 10-20 =-10 * multiplied by 10 * 20 = 200 / divided by 10 / 20 = 0.5 stroke / division returns the integer part of the division (quotient) 9 / / 2 the remainder of the output result 4% returns the remainder of the division 9% 2 = 1 times * power, power, power 2 * * 3 = 8 compound assignment operator description example = simple assignment operator c = a + b assigns the result of a + b operation to c = addition assignment operator c = an equivalent to c = c + a color = subtraction assignment operator c-= an is equivalent to c = c-a = multiplication assignment operator c = an is equivalent to the division assignment operator c / = a The assignment operator c / / = an is equivalent to c = c / a% = modulo (remainder) assignment operator c% = an is equivalent to c = c% axiom = power assignment operator c = c% * = an is equivalent to c = c% * a

Note:

All operations can be performed between numbers and numbers.

Multiplication can only be performed between a number and a string.

Only addition can be performed between strings.

Thank you for your reading, the above is the content of "what are the operation rules between different types of Python". After the study of this article, I believe you have a deeper understanding of what the operation rules between different types of Python are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Operations operators between types differences rules characters strings numbers remainder data arithmetic division learning multiplication content addition examples Boolean results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Shulou Tech Info Xiaomi vpn