python-基础day6

ascii
A : 00000010 8位 一个字节

unicode A : 00000000 00000001 00000010 00000100 32位 四个字节
中:00000000 00000001 00000010 00000110 32位 四个字节


utf-8 A : 00100000 8位 一个字节
中 : 00000001 00000010 00000110 24位 三个字节


gbk A : 00000110 8位 一个字节
中 : 00000010 00000110 16位 两个字节
1,各个编码之间的二进制,是不能互相识别的,会产生乱码。
2,文件的储存,传输,不能是unicode(只能是utf-8 utf-16 gbk,gb2312,asciid等)

py3:
str 在内存中是用unicode编码。
bytes类型
对于英文:
str :表现形式:s = 'alex'
编码方式: 010101010 unicode
bytes :表现形式:s = b'alex'
编码方式: 000101010 utf-8 gbk。。。。

对于中文:
str :表现形式:s = '中国'
编码方式: 010101010 unicode
bytes :表现形式:s = b'x\e91\e91\e01\e21\e31\e32'
编码方式: 000101010 utf-8 gbk。。。。

li=[11,22,33,44,55,66,77,88,99,90]
dic={}
high_number=[]
less_number=[]
for i in li:
    if i==66:continue
    if i>66:
        high_number.append(i)
    else:
        less_number.append(i)
dic.setdefault('k1',high_number)
dic.setdefault('k2',less_number)
print(dic)
#购物车
li=['手机','电脑','鼠标垫','游艇']
flag=True
while flag:
    for i in li:
        print('{}\t{}'.format(li.index(i)+1,i))
    num_of_choice=input("请输入商品序号或者按Q/q退出:")
    if num_of_choice.isdigit():
        num_of_choice=int(num_of_choice)
        if 0<num_of_choice<=len(li):
            print(li[num_of_choice-1])
        else:
            print("请输入有效数字")
    elif num_of_choice.upper()=='Q':
        flag=False
    else:
        print("请输入数字")

 

posted on 2019-05-07 20:46  orange小橘子  阅读(136)  评论(0编辑  收藏  举报