目录
位运算符:&, |, ~, 使用的样例,以及二进制操作的过程
1.\t的使用,用样例验证
print(123, '\t', end='')
print(1)
print(12345, '\t', end='')
print(1)
print(1234, '\t', end='')
print(1)
123 1
12345 1
1234 1
Process finished with exit code 0
2.什么是空语句
while 2 > 1:
pass
Process finished with exit code -1
3.运算符的使用:
算术运算符:所有的英文,以及使用样例
加:Add
减:subtract
乘:multiply
除:divide
取余:mold
取商:loordiv
幂: **
print(2 + 3) # add
print(2 - 3) # sub
print(2 * 3) # mul
print(2 / 3) # div
print(3 % 1) # mod
print(3 // 2) # floordiv
print(3 ** 2) # **
5
-1
6
0.6666666666666666
0
1
9
Process finished with exit code 0
比较运算符:所有的英文,以及使用样例
等于:==:equal -> eq
不等于:!=: not equal -> ne
大于:>: greater than -> gt
大于等于:>=: greater than equal -> ge
小于:<: less than: lt
小于等于:<=: less than equal -> le
print(2 == 3) # equal -> eq
print(2 != 3) # not equal -> ne
print(2 > 3) # greater than -> gt
print(2 >= 3) # greater than equal -> ge
print(2 < 3) # less than: lt
print(2 <= 3) # less than equal -> le
False
True
False
False
True
True
Process finished with exit code 0
位运算符:&, |, ~, 使用的样例,以及二进制操作的过程
&:按位或
print(0 & 1)
# & 用二进制按位与
# 0 =>0000
# 1 =>0001
# => 0000=>0
0
Process finished with exit code 0
|:按位与
print(0 | 1)
# | 用二进制按位或
# 0 =>0000
# 1 =>0001
# => 0001=>1
1
Process finished with exit code 0
~:非