目录
大于等于:>=: greater than equal -> ge
小于等于:<=: less than equal -> le
(3)位运算符:&, |, ~, 使用的样例,以及二进制操作的过程
1.\t的使用,用样例验证
print(123, '\t', end='')
print(1)
print(12345, '\t', end='')
print(1)
print(1234, '\t', end='')
print(1)
D:\python\python.exe D:/python/python_code/circle_control.py
123 1
12345 1
1234 1
Process finished with exit code 0
2.什么是空语句
while 2 > 1:
pass
D:\python\python.exe D:/python/python_code/circle_control.py
Process finished with exit code -1
3.运算符的使用:
(1)算术运算符:所有的英文,以及使用样例
加:Add
减:subtract
乘:multiply
除:divide
取余:mold
取商f: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) # **幂
D:\python\python.exe D:/python/python_code/circle_control.py
5
-1
6
0.6666666666666666
0
1
9
Process finished with exit code 0
(2)比较运算符:所有的英文,以及使用样例
等于:==: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
D:\python\python.exe D:/python/python_code/circle_control.py
False
True
False
False
True
True
Process finished with exit code 0
(3)位运算符:&, |, ~, 使用的样例,以及二进制操作的过程
&:按位或
print(0 & 1) # & 用二进制按位与
# 0 =>0000
# 1 =>0001
# => 0000=>0
D:\python\python.exe D:/python/python_code/circle_control.py
0
Process finished with exit code 0
|:按位与
print(0 | 1) # | 用二进制按位或
# 0 =>0000
# 1 =>0001
# => 0001=>1
D:\python\python.exe D:/python/python_code/circle_control.py
1
Process finished with exit code 0
~:非
print(~1) # ~ 非
# 1 => 00001
# 1 => 11110(补码) => 14
# 1 => 11110(反码=补码-1)=>11101
# => 10010(取反拿到源码)=> -2
D:\python\python.exe D:/python/python_code/circle_control.py
-2
Process finished with exit code 0