一,喂,你了解编码吗?
1,编码历史
最开始使用是:ASCII码,但是其只能表示256种可能,太少,
So,创办了万国码 Unicode。
16表示一个字符不行,32位表示一个字符。
A 01000001010000010100000101000001
B 01000010010000100100001001000010
我 01000010010000100100001001000010
Now:Unicode 升级 utf-8 utf-16 utf-32
2,别人不知道的小知识
进一步介绍:
首先你要知道:8位 = 1字节bytes!
utf-8: 一个字符最少用8位去表示,英文用8位 表示: 一个字节
欧洲文字用16位去表示:两个字节
中文用24 位去表示: 三个字节
utf-16 :一个字符最少用16位去表示。
GBK:中国人自己发明的,一个中文用两个字节 16位去表示。
另外再补充点小知识:
1bit ——————— 8bit = 1bytes
1byte —————— 1024byte = 1KB
1KB —————— 1024kb = 1MB
1MB —————— 1024MB = 1GB
1GB —————— 1024GB = 1TB
二,快来小试牛刀!
1,先来看看我们昨儿的homework
第一题:使用while循环输入 1 2 3 4 5 6 8 9 10
count = 0
while count < 10:
count += 1 # count = count + 1
if count == 7:
continue
print(count)
第二题:输出 1-100 内的所有奇数
方法一:
count = 1
while count < 101:
print(count)
count += 2
方法二:
count = 1
while count < 101:
if count % 2 == 1:
print(count)
count += 1
第三题:求1-2+3-4+5 … 99的所有数的和
sum = 0
count = 1
while count < 100:
if count % 2 == 0:
sum = sum - count
else:
sum = sum + count
count += 1
print(sum)
2,你听过格式化输出吗?
%s %d
name = input('请输入姓名')
age = input('请输入年龄')
height = input('请输入身高')
msg = "我叫%s,今年%s 身高 %s" %(name,age,height)
print(msg)
3,给你讲点神奇的东西
在 python 中,while … else 在循环条件为 false 时执行 else 语句块:
count = 0
while count <= 5:
count += 1
if count == 3:
break
print("Loop", count)
else:
print("循环正常执行完啦")
print("-----out of while loop ------")
上述程序的执行结果是:
Loop 1
Loop 2
-----out of while loop ------
4,听说过逻辑运算吗?
优先级,()> not > and > or
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
再加点料:
'''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
'''x and y x True,则返回y'''
# print(1 and 2)
# print(0 and 2)
# print(2 or 1 < 3)
# print(3 > 1 or 2 and 2)
上面的输出是:
2
0
2
True
最后做一个最难的:
print(4 > 2 or 5)
恭喜你做对了,答案是:
True