while 无限循环。
基本结构:
while 条件:
循环体
初识循环
while True:
print(‘狼的诱惑‘)
print(‘我们不一样‘)
print(‘月亮之上‘)
print(‘庐州月‘)
print(‘人间‘)
循环如何终止?
改变条件
flag = True
while flag:
print(‘狼的诱惑‘)
print(‘我们不一样‘)
print(‘月亮之上‘)
flag = False
print(‘庐州月‘)
print(‘人间‘)
# 练习题: 1~ 100 所有的数字
count = 1
flag = True
while flag:
print(count)
count = count + 1
if count == 101:
flag = False
count = 1
while count < 101:
print(count)
count = count + 1
break
while True:
print(‘狼的诱惑‘)
print(‘我们不一样‘)
print(‘月亮之上‘)
break
print(‘庐州月‘)
print(‘人间‘)
print(111)
continue
#continue:退出本次循环,继续下一次循环
flag = True
while flag:
print(111)
print(222)
flag = False
continue
print(333)
#while else: while 循环如果被break打断,则不执行else语句。
count = 1
while count < 5:
print(count)
if count == 2:
break
count = count + 1
else:
print(666)
当你你需要重复之前的动作,输入用户名密码,考虑到while循环。
当你遇到这样的需求:字符串中想让某些位置变成动态可传入的,首先要考虑到格式化输出。
# msg = ‘‘‘------------ info of Jarvis -----------
# Name : Jarvis
# Age : 18
# job : Student
# Hobbie: python
# ------------- end -----------------‘‘‘
# 制作一个公共的模板
# 让一个字符串的某些位置变成动态可传入的。
# 格式化输出
# name = input(‘请输入你的姓名:‘)
# age = input(‘请输入你的年龄:‘)
# job = input(‘请输入你的工作:‘)
# hobby = input(‘请输入你的爱好:‘)
# % 占位符 s --> str d i r
# msg = ‘‘‘------------ info of %s -----------
# Name : %s
# Age : %d
# job : %s
# Hobbie: %s
# ------------- end -----------------‘‘‘ % (name, name, int(age), job, hobby)
# print(msg)
# 坑:在格式化输出中,% 只想表示一个百分号,而不是作为占位符使用
#msg = ‘我叫%s,今年%s,学习进度1%%‘ % (‘Jarvis‘, 18)
#print(msg)
运算符:算数运算符 + -,比较运算符 > ==,赋值运算符=,+=,逻辑运算符,and or, 成员运算符。
i1 = 2
i2 = 3
print(2 ** 3)
print(10 // 3)
print(10 % 3)
print(3 != 4)
count = 1
count = count + 1
count += 1
print(count)
# and or not
# 1 在没有()的情况下,优先级:not > and > or,同一优先级从左至右依次计算
# 情况1:两边都是比较运算
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
# print(True or False)
# 情况2:两边都是整数
‘‘‘
x or y , x为真,值就是x,x为假,值是y
‘‘‘
# print(1 or 2)
# print(3 or 2)
# print(4 or 2)
# print(-1 or 2)
# print(0 or 2)
# print(1 and 2)
数据类型之间的转换
# str ---> int : 只能是纯数字组成的字符串
s1 = ‘00100‘
print(int(s1))
# int ----> str
i1 = 100
print(str(i1),type(str(i1)))
# int ---> bool : 非零即True ,0为False。
i = 0
print(bool(i))
# bool ---> int
print(int(True)) # 1
print(int(False)) # 0
计算机存储文件,存储数据,以及将一些数据信息通过网络发送出去,存储发送数据什么内容?底层都是01010101.
真正密码本:
第一版:
第二版:
密码本:01010110 二进制与 文字之间的对应关系。
最早期的密码本:
gbk: 英文字母,数字,特殊字符和中文。国标
Unicode: 万国码:把世界上所有的文字都记录到这个密码本。
Utf-8:升级:最少用8bit1个字节表示一个字符。
单位转换
8bit = 1byte
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB
1024TB = 1PB
1024TB = 1EB
1024EB = 1ZB
1024ZB = 1YB
原文:https://www.cnblogs.com/rgz-blog/p/12685480.html