Python基础(五):运算符
作者:互联网
运算符
运算符 | 描述 | 示例 |
---|---|---|
+ | 加 | 2 + 4 = 6 |
- | 减 | 2 - 4 = -2 |
* | 乘 | 2 * 4 = 8 |
** | 幂 | 2 ** 4 = 16 |
/ | 除 | 2 / 4 = 0.5 |
// | 除后向下取整 | 2 // 4 = 0 |
% | 字符串翻译,或者求余数 | 2 % 4 = 2 |
< | 小于 | 4 < 4 == False |
> | 大于 | 4 > 4 == False |
<= | 小于等于 | 4 <= 4 == True |
>= | 大于等于 | 4 >= 4 == True |
== | 等于 | 4 == 5 == False |
!= | 不等于 | 4 != 5 == True |
() | 括号 | len('hi') == 2 |
[] | 方括号(表示列表) | [1, 3, 4] |
{} | 大括号(表示字典) | {'x': 5, 'y': 10} |
@ | 修饰器符 | @classmethod |
, | 逗号 | range(0, 10) |
: | 冒号 | def x(): |
. | 点 | self.x = 10 |
= | 赋值 | x = 10 |
; | 分号(功能同换行) | print('hi'); print('there') |
+= | 加后赋值 | x = 1; x += 2 |
-= | 减后赋值 | x = 1; x -= 2 |
*= | 乘后赋值 | x = 1; x *= 2 |
/= | 除后赋值 | x = 1; x /= 2 |
//= | 除后舍余并赋值 | x = 1; x //= 2 |
%= | 求余后赋值 | x = 1; x %= 2 |
**= | 求幂后赋值 | x = 1; x **= 2 |
标签:除后,10,False,Python,基础,运算符,等于,赋值 来源: https://www.cnblogs.com/pchance/p/12906542.html