while 空格 条件 冒号
缩进 循环体
while 5>4:
print("Hello World!")
数字中非0的都是True
# 正序25~57
# count = 25
# while count <= 57:
# print(count)
# count += 1
# 倒叙57~25
# count = 57
# while count >= 25:
# print(count)
# count -= 1
break 终止当前循环,break下面的循环体代码不执行
continue 跳过本次循环,继续下一次循环(下面的代码不执行) #continue伪装成循环体中的最后一行代码
? 下面的循环体代码不执行
条件可以控制while循环
? 1.自己修改条件
? 2.break
# num = int(input("请输入数字:"))
# while num == 1:
# user = input("请输入用户名:")
# pwd = input("请输入密码:")
# if user == "zcy" and pwd == "123":
# print("登陆成功!")
# break
# else:
# print("用户名或密码错误!")
# else:
# print("退出成功!")
while else: while 条件成立的时候就不执行了,条件不成立的时候就执行else
按位置顺序传递,占位和补位必须要一一对应
如果要在字符串中输出%时,用%%转义
name = input("姓名:")
age = input("年龄:")
msg = ‘姓名:%s,年龄:%d‘%(name,int(age))
print(msg)
? % -- 占位
? %s -- 占字符串的位
? %d -- 占数字位
? %% -- 转义成普通的%
name = input("姓名:")
age = input("年龄:")
msg = ‘姓名:{},年龄:{}‘.format(name,int(age))
print(msg)
name = input("姓名:")
age = input("年龄:")
msg = ‘姓名:{1},年龄:{0}‘.format(int(age),name)
print(msg)
name = input("姓名:")
age = input("年龄:")
msg = f‘姓名{name},年龄{age}‘
print(msg)
? + 加
? - 减
? * 乘
? / python2获取的是整数 python3获取的是浮点数
? //(整除--地板除)
? ** 幂(次方)
? % 模(取余)
? > 大于
? < 小于
? == 等于
? != 不等于
? >= 大于等于
? <= 小于等于
? = 赋值
? += 自加
? -= 自减
? *= 自乘
? /= 自除
? //= 自地板除
? **= 自幂
? %= 自余
? and 与
? or 或
? not 非
()> not > and > or
and 都为真的时候取and后面的值
? print( 3 and 4) #4
and 都为假的时候取and前面的值(前面是假的时,and后面的不用判断)
? print( 0 and False) #0
and 一真一假时取假的(前面是假的时,and后面的不用判断)
? print( 0 and 4) #0
? print( 4 and 0) #0
or 都为真的时候取or前面的值(前面是真的时,or后面的不用判断)
? print( 3 or 4) #3
or 都为假的时候取or后面的值
? print( 0 or False) #False
or一真一假取真的(前面是真的时,or后面的不用判断)
? print( 0 or 4) #4
? print( 4 or 0) #4
? in 存在
? not in 不存在
? Ascii(美国) 不支持中文
? GBK(国标,也称GBK2312) 英文 8位(1Bytes) 中文 16位(2Bytes)
? Unicode(万国码) 英文16位(2Bytes) 中文32位(4Bytes)
? UTF-8(可变长编码) 英文8位(1Bytes) 欧洲文16位(2Bytes) 亚洲(24位)(3Bytes)
? Linux -- UTF-8
? Mac -- UTF-8
? Windows --GBK
print(a,b,c,d,sep = "\n") #sep = "\n" 换行
原文:https://www.cnblogs.com/yzm1017/p/13570916.html