day6 python全栈学习笔记

1、编码

ascii
A :00000010 8位 一个字节

unicode
A : 00000000 00000000 00000000 00000010 32位 4个字节

utf-8
A : 0010 0000 8位 一个字节
中 :00000010 00000010 00000110 24位 3个字节

gbk
A : 00000010 8位 一个字节
中:00000010 00000010 16位 2个字节

1、各个编码之间的二进制,是不能互相识别的,会产生乱码
2、文件的存储,传输,不能是unicode,(只能是utf-8,gbk,gb2312,acsii码)

py3: str 在内存中是用unicode编码
bytes类型

在内存中编码格式为unicode,但是存储在硬盘,和传送文件时的编码格式,都是’utf-8‘,’gbk‘
因为unicode 太站流量

2、小知识点整合

#数字,字符串,小数据池
# -5 ---256 用的同一个地址
#字符串也有一些是在同一个数据池
li = [1,2,3]
li2 = li
print(id(li),id(li2))


i1 = 8
i2 = 8
print(i1 is i2)

s = 'alex'
s1 = s.encode('utf-8')
s2 = s.encode('gbk')
print(s1)
print(s2)

2、购物车

#商品放在货架上
li = [
    {'name':'苹果','price':10},
    {'name':'香蕉','price':20},
    {'name':'橘子','price':30},
]

#看看钱多少
shopping_car = {}
print('欢迎光临老毛孩旗舰店')
money = int(input('您有多少钱'))
while 1:
    if int(money) > 0:
        for i,k in enumerate(li):
            print('序号{},商品{},价格{}'.format(i,k['name'],k['price']))
        choose = input('请输入您要购买的商品序号')
        if choose.isdigit() and int(choose) < len(li):
            num = input('请输入购买的数量')
            if num.isdigit():
                if int(money) > li[int(choose)]['price']*int(num):
                    money = int(money) - li[int(choose)]['price'] * int(num)
                    if li[int(choose)]['name'] is shopping_car:
                        shopping_car[li[int(choose)]['name']] = shopping_car[li[int(choose)]['name']] + int(num)
                    else:
                        shopping_car[li[int(choose)]['name']] = int(num)
                    print('购物车中的商品有{},您的余额为{}'.format(shopping_car, money))
                else:
                    print('您的余额不够')
                    break
        else:
            print('输入序号!')

 

转载于:https://www.cnblogs.com/laomaohai/p/10053997.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值