• 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('输入序号!')
  • 相关阅读:
    平衡二叉树之RB树
    平衡二叉树之AVL树
    实现哈希表
    LeetCode Median of Two Sorted Arrays
    LeetCode Minimum Window Substring
    LeetCode Interleaving String
    LeetCode Regular Expression Matching
    PAT 1087 All Roads Lead to Rome
    PAT 1086 Tree Traversals Again
    LeetCode Longest Palindromic Substring
  • 原文地址:https://www.cnblogs.com/laomaohai/p/10053997.html
Copyright © 2020-2023  润新知