目录
#while判断条件非0
while 1:
print("你好") #无限打印“你好”
#while判断条件为0
while 0: #0的bool值为False
print("哈哈")
#人为打破的while循环,else不执行
i=1
while i<5:
print(i)
i+=1
else:
print("over")
#1,2,3,4,over
i=1
while i<5:
print(i)
i+=1
if i==3:
break #人为打破while循环
else:
print("over")
#1,2
#一个%代表占位
s="天气好%s%"%("好")
print(s) #ValueError: incomplete format。错误原因:%后没跟数据类型
#两个%代表转义
s="天气好%s%%"%("15")
print(s) #天气好15%
#f只有在python3.6之上才能使用
what="下雨"
a=f"今天{what}"
print(a) #今天下雨
a="我是{}{}".format("好","人")
print(a) #我是好人
'''
ascii (美国) 不支持中文
gbk (国标) 英文1字节 中文2字节
unicode (万国码) 英文2字节 中文4字节
utf-8 (可变长编码) 英文1字节 欧洲2字节 亚洲3字节
'''
''' 系统默认编码
linux --utf-8
mac --utf-8
windows --gbk
'''
''' 单位换算
1字节=8位
1Bytes=8bit
1024Bytes=1KB
1024KB=1MB
1024MB=1GB
1024GB=1TB
'''
# + - * / ...
python2:
-- 5/2=2
-- 5.0/2=2.5
-- ps:/除数和被除数都为整数,结果为得到商的整数部分;在除数或被除数加上小数点,得到正确值
python3:
-- 5/2=2.5
-- 5//2=2
-- ps:/得到准确值,//得到商的整数部分
> < == !=
= -= += *= ...
and 两边都为真取后面值 两边都为假取前面的
or 两边都为真取前面值,两边都为假取后面值
not
优先级: ()>not>and>or
#例子:1 and 2 or 3 not False and 4 or (1 and 2)
in
not in
原文:https://www.cnblogs.com/gaoyukun/p/11139468.html