运算(算术,逻辑,赋值)
算术运算:
+ (加法运算,对字符串起拼接作用)
- (减法运算)
* (乘法运算,对字符串起重复作用)
/ (除法运算)
// (整除运算)
** (幂运算)
赋值运算:
# "=" : c = a + b,将a+b的值赋给c
# "+=": 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
# "//=": a// = b 等效于 a = a // b
逻辑运算:
and: 两边必须全为真结果才为真,存在假结果就是假.
or: 两边有一个为真结果就为真,两边全是假结果才为假.
not: 非真即假,非假即真
逻辑运算时,先判断比较的结果是真还是假,and, or,not同时存在时,先计算括号里的,然后计算not,再计算and,最后计算or.
num or 0 ==>num; 0 or num ==>num; num1 or num2 ==>num1;
num and 0 ==>0; 0 and num ==>0; num1 and num2 ==>num2;
1 #T为True, F为False 2 print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ) #False 3 #F and T or F and T and T or F 4 #F or F and T or F 5 #F or F or F 6 #F 7 8 print(8 or 3 and 4 or 2 and 0 or 9 and 7) #8 9 #print(8 or 3 and 4 or 2 and 0 or 9 and 7) 10 #8 or 4 or 0 or 7 11 #8 12 13 print(3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2) #2 14 #T and 2 or F and 3 and 4 or T 15 #2 or F and 4 or T 16 #2 OR F or T 17 #2
.
无限的我,现在才开始绽放,从东边的第一缕阳光到西边的尽头