流程控制:while 循环编码
结构: while 条件:spa
循环体code
条件为真,循环体执行blog
条件为假,循环体不执行utf-8
while 循环为无限循环资源
循环终止语句unicode
continue break,字符串
cuntinue表示结束本次循环,继续下一循环input
break 表示跳出whileit
count=0 while count<100:#条件,只要小于100,执行下面的循环 print(count) if count==5; #条件,判断此条件,若成立 break #跳出整个循环 count+=1 #循环到此,count自加
注意:tab,缩进,一个循环走完再进行下一个循环,每一个循环体独立,
顶级代码必须顶行写,即若是一行代码运行不依赖任何条件,那他必须不能进行任何缩进
同一级别的代码,缩进必须一致
官方缩进:四个空格,或TAb键
count=0 while count<100: #条件判断 count+=1 #自加 if count>5 and count<95: #条件判断 continue #跳出本次循环,但不跳出while print(count) #打印12345...95 96 97 98 99 100
while else
while 可跟else 组合,若是while语句不被break终止,则执行else
count=0 while count<5: count+=1 print(count) else: #while 循环完,执行这里的else print('循环完成啦!')
当有break 时,
count=0 while count<6: count+=1 print(count) if count==3: break #这里有break 终止,跳出整个循环,不在执行else else: print('打印完成啦!')
格式化输入
%s表示字符串占位符,%d表示数字占位符
格式:msg='我想打印的内容% s ' %(name,age)
name=input('请输入你的名字:') age=int(input('请输入你的年龄')) sex=input('请输入你的性别') msg=''' --------------------上分隔线------------ 你的名字是:%s #%s表示占位符,后面括号的name 你的年龄是:%d 你的性别是:%s --------------------下行线-------------- ''' %(name,age,sex) #%就是把前面的字符串与后面的变量联系起来
检测数据类型
name=input('请输入你的名字:')
age=int(input('请输入你的年龄:'))
print(type(name)) #打印数据类型 ''str''
print(type(age)) #‘’int‘’
运算符
a%b # 取余 20%10 余数 0
a//b #取整 22//10 商的整数部分 2
赋值运算
+= c+=a c=c+a
-= c-=a c=c-a
*= c*=a c=c*a
/= c/=a c=c/a
%= c%=a c=c%a 取模赋值
**= c*=a c=c**a c的a次幂
//= c//=a c=c//a c/a 取整
逻辑运算
and 布尔 与,x为False,x and y 为False,x为True,继续判断y,y为True,返回True,y为False,返回False
or 布尔 或,x为True,返回True,x为False,继续判断y,y为真,返回真,y为假,返回假
not 布尔 非 对或者错
判断逻辑语句的True,False
3>4 or 4<3 and 1==1
1 < 2 and 3 < 4 or 1>2
2 > 1 and 3 < 4 or 4 > 5 and 2 < 1
1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8
1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
1, 在没有()的状况下not 优先级高于 and,and优先级高于or,即优先级关系为( )>not>and>or,
同一优先级 左往右计算。
2 , x or y , x为真,值就是x,x为假,值是y;
x and y, x为真,值是y,x为假,值是x。
编码初识
ASCII码 8位,一字节,首0, 128个字符,可拓展256个字符
Unicode(统一码、万国码、单一码)
unicode:万国码,将全部国家的语言文字都写入这个密码本。 起初:1个字符 16位 2个字节表示。 A: 01000001 01000001 b: 01000001 01100001 中:01000001 01100101 改版:1个字符 32位 4个字节表示。 A: 01000001 01000001 01000001 01000001 b: 01000001 01100001 01000001 01000001 中:01000001 01100101 01000001 01000001 浪费资源,占空间。utf-8: 最少用8位表示一个字符。 A: 01000001 一个字节 欧洲文字: 01000001 01100001 两个字节 中:01000001 01100101 01000001 三个字节 'old男孩':9个字节gbk:国标,只包含 中文,英文(英文字母,数字,特殊字符) A: 01000001 一个字节 中:01000001 01100101 两个字节8 bit == 1bytes1024bytes == kb1024kb == 1MB1024MB == 1GB1024GB == 1TB1024TB == 1PB