day02
今日内容
-
while循环的进阶
-
break -- 终止当前循环
-
continue -- 跳出本次循环,继续下次循环 (个人理解:当执行到continue的时候就认为是循环体中最后一行代码)
-
break 和 continue下方代码都不会被执行
-
while True: username = input("username:") password = input("password:") if username == "alex" and password == "alex3714": print("登录成功!") break else: print("账号或密码错误,请重新输入!") -
while else
-
count = 1 while count < 4: user = input("username:") pwd = input("password:") if user == "alex" and pwd =="alexdsb": print("ok") break else: print("错误!") count = count + 1 else: print("账号被锁定!")
-
-
while嵌套
-
msg = """ 1.登录 2.注册 3.随笔 4.文章 >>> """ while True: choose = input(msg) if choose == "1": print("=" * 50) count = 1 while count < 4: user = input("username:") pwd = input("password:") if user == "alex" and pwd == "alexdsb": print("OK") break else: print("错啦!") count = count + 1 if choose == "2": while True: print("这是注册!")
-
-
-
格式化输出
-
name = input("请输入姓名:") iphone = input("请输入电话号:") job = input('请输入职位:') email = input("请输入邮箱:") addr = input("请输入公司地址:") msg = """ ------------------ xxx info ------------------ 姓名 : %s 电话 : %s 职位 : %s 邮箱 : %s 公司地址 : %s ------------------ end ------------------ """%(name,int(iphone),job,email,addr) print(msg) -
%方式进行填充的时候是按照位置填充,占得位置和填充的位置必须要一 一对应
-
msg = "%s现在目前学习进度为80%%"%(input("name:")) print(msg) # %% 就是转义成普通的%号 -
扩展 -- f-strings
-
# f - strings -- python3.6版本及以上才能使用 name = input("请输入姓名:") iphone = input("请输入电话号:") job = input('请输入职位:') email = input("请输入邮箱:") addr = input("请输入公司地址:") msg = f""" ------------------ xxx info ------------------ 姓名 : {name} 电话 : {iphone} 职位 : {job} 邮箱 : {email} 公司地址 : {addr} ------------------ end ------------------ """ print(msg)
-
-
-
运算符
-
算法运算符 + - * / // % **
-
比较运算符 > < >= <= == !=
-
赋值运算符 = += -= *= /= //= %= **=
-
逻辑运算符 and or not

- and都为真时才是真
- and都为真时选择and右边的内容
- and都为假时选择and左边的内容
- or 一个为真就是真
- or都为真时选择or左边的内容
- or都为假时选择or右边的内容
- 优先级
- () > not > and > or
- 计算顺序
- 从左向右
- and都为真时才是真
-
成员运算
- in 在
- not in 不在
-
-
编码初识
-
ascii 不执行中文
-
gbk 国标
- 英文 1个字符(abc) 使用1个字节 == 8位(0or1)
- 中文 1个字符(你) 使用2个字节 == 16位(0or1)
-
unicode 万国码
- 英文 和 中文 1个字符 使用 4个字节 == 32位
-
utf-8
- 英文 1个字符 使用1个字节 == 8位
- 欧洲 1个字符 使用2个字节 == 16位
- 亚洲 1个字符 使用3个字节 == 24位
-
单位转换
- 1Bytes(字节) == 8bit(位)
- 1KB == 1024Bytes
- 1MB == 1024KB
- 1GB == 1024MB
- 1TB == 1024GB (常用范围)
- 1PB == 1024TB
- 1EB == 1024PB
-
进制转换

-
十进制转换二进制
- 整除
- 码位

-
二进制转十进制
- 幂运算
- 码位
-
使用计算机进行进制转换
- 10 --- 2
- bin
- 2 --- 10
- int
- 10 --- 2
-
-

浙公网安备 33010602011771号