python基础(七)

目录

1.\t的使用,用样例验证

2.什么是空语句

3.运算符的使用:

(1)算术运算符:所有的英文,以及使用样例

加:Add

减:subtract

乘:multiply

除:divide

取余:mold

取商f:loordiv

幂: **

(2)比较运算符:所有的英文,以及使用样例

等于:==:equal -> eq

不等于:!=: not equal -> ne

大于:>: greater than -> gt

大于等于:>=: greater than equal -> ge

小于:<: less than: lt

小于等于:<=: 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nemophilistf.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值