赋值运算符
赋值运算符还是无需多说,只看下面Python赋值运算符内容表
运算符 | 名称 | 例子 | 说明 |
---|---|---|---|
= | 直接赋值 | a = b | 把b的值直接给a |
+= | 加赋值 | a += b | 等价于a = a + b |
-= | 减赋值 | a -= b | 等价于a = a - b |
*= | 乘赋值 | a *= b | 等价于a = a * b |
/= | 除赋值 | a /= b | 等价于a = a / b |
%= | 取余赋值 | a %= b | 等价于a = a % b |
**= | 幂赋值 | a **= b | 等价于a = a ** b |
//= | 整除赋值 | a //= b | 等价于a = a // b |
其他运算符
Python还有其他的一些运算符,先介绍两个“测试”运算符,同一性测试运算符和成员测试运算符。
同一性测试运算符
这种运算符就是测试两个对象是否同一个对象,类似 运算符,不同之处在于 (这个黄色不知道怎么去掉)是测试两个对象的内容,而同一性测试运算符只测试对象。
同一性测试运算符有两个:is和is not,is是判断同一,is not 是判断不是同一。
成员测试运算符
成员测试运算符可以测试在一个序列对象中是否包含某一个元素(所谓成员),成员测试运算符有两个:in和not in。