1.格式化输出
在字符串中 如有 % 就代表占位符 , %s表示占用的是字符串格式的, %d就代表占用的是数字
name = input("姓名:") age = int(input("年龄:")) job = input("工作:") hobbie = input("爱好:") msg = ''' ------------ info of %s ----------- Name : %s Age : %d job : %s Hobbie: %s ------------- end ----------------- ''' %( name , name, age, job,hobbie) print(msg)
输出
姓名:huihui 年龄:18 工作:学生 爱好:女 ------------ info of huihui ----------- Name : huihui Age : 18 job : 学生 Hobbie: 女 ------------- end -----------------
2.while else
count = 0 while count <= 5: count += 1 print("Loop",count) if count == 4: break while else 当while循环被break打断,则不走else程序。 else: print("循环正常执行完啦") print("-----out of while loop ------")
输出
Loop 1 Loop 2 Loop 3 Loop 4 -----out of while loop ------
3.运算符
0 == F(and 如果有0 就是0 都是真选后边)(or 如果有0 不选0 都是真选前面)
print(1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # 3<4 是T 所以是T print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ) # not后面是T 所以是F print(8 or 3 and 4 or 2 and 0 or 9 and 7) #8 print(0 or 2 and 3 and 4 or 6 and 0 or 3) #4 print(6 or 2 > 1) # 6 or T 6 print(3 or 2 > 1) print(0 or 5 < 4) # 0 or F 0是F F print(5 < 4 or 3) # F or 3 3 print(2 > 1 or 6) # T or 6 T print(3 and 2 > 1) # 3 and T T print(0 and 3 > 1) # 0 and T 0 print(2 > 1 and 3) # T and 3 3 print(3 > 1 and 0) # T and 0 0
4.编码初识
初代编码:ascii
只有字符,英文大小写
00100000 只有8位 8位为一字节
一字节 == 一字符
Unicode:万国码 全球的语言都能写
初始的时候是 16位
两个字节 == 一字符
升级后 32位
四个字节 == 一个字符
浪费空间
对Unicode在升级 - utf-8:
utf-8 最少8位为一字符 (英文)
欧洲文字为16位为一字符 (日韩)
汉语 24位为一字符
gbk:国家标准。
a : 01100001
中: 01100001 01100001
8位 1个byte
1024bytes 1kb
1024kb 1MB
1024MB 1GB
1024GB 1TB