编码与解码PY

介绍解码与编码

首先分别有ascii码,gbk码,unicode码,utf-8码,utf-16码

  • ASCII码 :不支持中文支持英文,符号数字(占用一个字节 8位)

  • GBK码:支持中文数字英文符号,英文中文占用两个字节 16位

  • unicode:万国码支持各国语言,英文中文都是占用32位 4个字节

  • UTF -8 :升级版的万国码,以8个字节为一个段落,不满八位,自动以一个字节存储处理,节省了电脑的空间,最少使用一个位来存储,英文和ASCII一样占用8位,中文占用24位 3个字节

  • UTF - 16:很少使用,最少占用16位

    python3中默认使用是Unicode码,显示所输出的内容,Unicode不可以做文件传输和存储因为占用内存太大,浪费空间

    传输和储存使用的是bytes类型以二进制将加快运行速度pycharm使用utf-8

    • 编码解码使用
    s ='你好'
    print(s.encode('utf-8'))      #b'\xe4\xbd\xa0\xe5\xa5\xbd'每三个代表一个字,一个子由3个字节构成也就是24位  浣犲ソ
    s1= s.encode("utf-8")
    print(s.encode('gbk'))        #b'\xc4\xe3\xba\xc3'  每两个算一个子,一个自由2个字节构成16位
    
    用什么编码就用什么解码

    is和==的区别

    • is 比较内存地址 查内存地址用id() 这个比较重要

      num = "y"*20
      num1 ="y"*20
      print(num is num1)
      

      小数据池(-5 ~ 256)is 在这个范围内内存地址是相等的如果超过就不一定

      字符串中不能含有特殊符号

      字符串单个字符*20以内地址包括20都是相等的

    • == 用来比较两变的值是否相等

数据类型的补充

join()与split()有着相反的功能
join可以将可迭代的对象进行用特定的内容进行拼接'**'
split()使用'*'特定内容进行切割产生列表
join可以将列表转换成字符串,字符串按照元素进行拼接
列表中的元素进行删除此操作,循环新列表,删除老列表
在进行迭代过程中列表字典的长度都是不可更改的
fromkeys  字典中使用的函数  dict.fromkeys('abs','a')
将abs进行迭代每一个迭代对象都配用一个a字符后面你这个字符是公共的
# 音乐会皇家会所 邀请十位大佬来评分评分必须大于5小于10
# lst =[]
# count =1
# while count<=10:
#     score = int(input("请%s位评委评分:" % count))
#     if score<5 or score>10:
#         print("老哥没良心呀!看评分规则")
#         continue
#     else:
#         lst.append(score)
#     count += 1
# print(lst)
# for el in range(1,11):
#     print('第%d位评委评分:%d' % (el,lst[el-1]))
# score ={}
# lst = ['阿凡达','嘻游记','红楼梦','金刚']
# for el in lst:
#     print(el)
#     score[el]=int(input("(%s)请评委评分:" %  el))
# print(score)
# 读数字
# sum =''
# read = {"-":"fu","1":'yi','2':"er",'3':"san",'4':'si','5':'wu','6':'liu'}
# num = input("请输入一个数字:")
# for el in num:
#     if el in read:
#         sum =sum + read[el] +' '
# print(sum[:-1])
# ? 陋比查车牌系统
# car_card = ['冀D30446','冀D30447','黑D30446','京C66666']
# local={'黑':'黑龙江','冀':'河北','京':'北京'}
# count =0
# a =0
# b =0
# car ={}
# for el in car_card:
#     if '冀' in el:
#         count += 1
#     elif "黑" in el :
#         a += 1
#     else:
#         b += 1
# for el in local:
#     if el == '冀':
#         car[local[el]] = count
#     elif el =="京":
#         car[local[el]] = a
#     else:
#         car[local[el]] = b
# print(car)
# /#升级版
# cars = ['黑A333333','冀B4444444','沪Q99999','冀D66666','琼B9999999','琼C62666','京B777777','京']
# locals = {'黑':'黑龙江','冀':'河北','沪':'上海','琼':'海南','京':'北京'}
# car_people={}
# for el  in cars:
#      if car_people.get(locals[el[0]]) == None:
#          car_people[locals[el[0]]] = 1
#      else:
#          car_people[locals[el[0]]] += 1
# print(car_people)
####干掉主播
# star = {'卢本伟':1,'冯提莫':1,'散打哥':1,'罗爬格子':1}
# avg = 0
# sum = 0
# new_lst ={}
# for el in star:
#      sum =sum + star.get(el)
#      new_lst[el]=star.get(el)
# avg= sum/len(star)
# print(new_lst)
# for el in new_lst:
#      if star.get(el)<avg:
#          star.pop(el)
# print(star)

posted @ 2020-04-09 16:16  巴比哥  阅读(214)  评论(0)    收藏  举报