Python中一些运算符的使用

目录

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

2.什么是空语句

3.运算符的使用:算术运算符:所有的英文,以及使用样例

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

位运算符:&, |, ~, 使用的样例,以及二进制操作的过程

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

~:非

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值