栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python基础(七)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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:pythonpython.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:pythonpython.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:pythonpython.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:pythonpython.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:pythonpython.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:pythonpython.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:pythonpython.exe D:/python/python_code/circle_control.py
-2

Process finished with exit code 0

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/976869.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号