1、格式化(模板)输出:
name = input('请输入名字:') age = input ('请输入年龄:') height = input ('请输入身高') msg = "我叫%s,今年%s,身高%s,进度3%%" %(name,age,height) print(msg)
在格式化输出中,如果单纯你的表示%,就再加一个%,起转译作用。
name = input('请输入名字:') age = 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)
%:占位符 s:字符串 d:数字
2、while else:
count = 0
while count <= 5 : count += 1 if count == 3:break print("Loop",count) else: print("循环正常执行完啦") print("-----out of while loop ------")
3、初始编码:
电报,电脑的传输,存储都是01010101
最早的'编程密码本' ASCII 码涵盖了英文字母大小写,特殊字符,数字。
01010101
ASCII码只能表示256种可能,太少,
创办了万国码 unicode
16位表示一个字符不行,32位表示一个字符。
A 01000001010000010100000101000001
B 01000010010000100100001001000010
我 01000010010000100100001001000010
Unicode 升级 utf-8 utf-16 utf-32
8位 = 1字节bytes
utf-8 一个字符最少用8位去表示
英文用8位 去表示 一个字节
欧洲文字用16位去表示 两个字节
中文用24 位去表示 三个字节
utf-16 一个字符最少用16位去表示
gbk 中国人自己发明的,一个中文用两个字节 16位去表示。
各单位间的转换
11000000
1bit 8bit = 1bytes
1byte 1024byte = 1KB
1KB 1024kb = 1MB
1MB 1024MB = 1GB
1GB 1024GB = 1TB
4、运算符
(1)逻辑运算
and or not
优先级,()> not > and > or
当or、and左右两边为不等式时
print(2 > 1 and 1 < 4) print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2) #T or T or F #T or F #T print(3>4 or 4<3 and 1==1) # F print(1 < 2 and 3 < 4 or 1>2) # T print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
当or、and左右两边为数字时
'''x or y x True,则返回x''' print(1 or 2) # 1 print(3 or 2) # 3 print(0 or 2) # 2 print(0 or 100) # 100 print(2 or 100 or 3 or 4) # 2 print(0 or 4 and 3 or 2) #2
'''x and y x True,则返回y''' print(1 and 2) print(0 and 2)
#ps int ----> bool 非零转换成bool True 0 转换成bool 是False print(bool(2)) print(bool(-2)) print(bool(0)) #bool --->int print(int(True)) # 1 print(int(False)) # 0