Home >Backend Development >Python Tutorial >Arithmetic operators and comparison operators for basic learning in Python
In recent years, as the popularity of Python in the Internet industry has only increased, many people are learning Python, but if they want to truly learn it well, they must lay a good foundation. The main content of this article is about Python's arithmetic operators and comparison operators, with sample code explanations. Interested friends can learn about it.
Arithmetic operators
Description | Example | |
---|---|---|
Add - Add two objects | a b Output result 31 | |
Subtract - Get a negative number or subtract one number from another number | a - b Output result-11 | |
Multiplication - Multiply two numbers or return a string repeated several times | a * b Output result 210 | |
Division- b % a Output result 1 | ** | |
a**b is 10 raised to the 21st power | // | |
9//2 Output result 4, 9.0//2.0 Output result 4.0 | Example code: | |
1 - c 的值为: 31 2 - c 的值为: 11 3 - c 的值为: 210 4 - c 的值为: 2.1 5 - c 的值为: 1 6 - c 的值为: 8 7 - c 的值为: 2 |
Comparison operator |
(a == b) Return False. | != | |
---|---|---|
(a != b) Returns true. | > | |
(a > b) Returns False. | 06a68011356bf656d4dc21ead41287f6= | |
(a >= b) Returns False. | <= | |
(a <= b) returns true. | The following examples demonstrate the operation of all comparison operators in Python: | |
1 - a 不等于 b 2 - a 不等于 b 3 - a 大于等于 b 4 - a 大于 b 5 - a 小于等于 b 6 - b 大于等于 b | Related tutorials:Python3 video tutorial |
The above is the detailed content of Arithmetic operators and comparison operators for basic learning in Python. For more information, please follow other related articles on the PHP Chinese website!