0.编码解码

>encode和decode
a = "你好"
s = a.encode("GBK")
print(s)
# b'\xc4\xe3\xba\xc3' 每一个\x是一个字节,每一个GBK占16bit,2个bytes,那么两个中文就是4个bytes,验证成功 s1 = a.encode("UTf-8")
print(s1)
# b'\xe4\xbd\xa0\xe5\xa5\xbd' 每一个\x是一个字节,每一个UTF-8中文占24bit,3个bytes,那么两个中文就是6个bytes,验证成功 b = "hello"
b1 = b.encode("utf-8")
print(b1)
# b'hello' 在编解码英文时,不会换成16进制,会直接传输 b2 = b.encode("gbk")
print(b2)
# b'hello' c = b'\xe4\xbd\xa0\xe5\xa5\xbd' # 解码,
c1 = c.decode("utf-8")
print(c1)
# 你好

1.is和==的区别

is和==
# == 双等表⽰示的是判断是否相等, 注意. 这个双等比较的是具体的值.⽽而不是内存地址
# is 比较的是数据存储在内存中的地址 id
aaa = "hello,world"
bbb = "hello,world"
print(id(aaa))
#
print(id(bbb)
# 31339568 #返回的是同一个id,证明在内存中两个变量指向了同一个数据,这个就是针对字符串特有的小数据池 lst = [1, 2, 4]
print(id(lst))
#
lst1 = [1, 2, 4]
print(id(lst1))
#
# 虽然两个列表的值是一样的,但是列表是不一样的, 两个列表中的值都是相同的指向

is和==,encode和decode的更多相关文章

  1. [LeetCode] Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  2. 【python】python新手必碰到的问题---encode与decode,中文乱码[转]

    转自:http://blog.csdn.net/a921800467b/article/details/8579510 为什么会报错“UnicodeEncodeError:'ascii' codec ...

  3. LeetCode Encode and Decode Strings

    原题链接在这里:https://leetcode.com/problems/encode-and-decode-strings/ 题目: Design an algorithm to encode a ...

  4. Encode and Decode Strings

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  5. encode和decode

    Python字符串的encode与decode研究心得乱码问题解决方法 为什么会报错“UnicodeEncodeError: 'ascii' codec can't encode characters ...

  6. 【python】浅谈encode和decode

    对于encode和decode,笔者也是根据自己的理解,有不对的地方还请多多指点. 编码的理解: 1.编码:utf-8,utf-16,gbk,gb2312,gb18030等,编码为了便于理解,可以把它 ...

  7. 271. Encode and Decode Strings

    题目: Design an algorithm to encode a list of strings to a string. The encoded string is then sent ove ...

  8. [LeetCode#271] Encode and Decode Strings

    Problem: Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...

  9. Encode and Decode Strings 解答

    Question Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...

  10. python encode和decode函数说明【转载】

    python encode和decode函数说明 字符串编码常用类型:utf-8,gb2312,cp936,gbk等. python中,我们使用decode()和encode()来进行解码和编码 在p ...

随机推荐

  1. 使用js调用摄像头拍照

    在一些浏览器里已经可以使用web api调用摄像头功能了. 基于此可以经行拍照摄像功能,网上找了些资料,然后实现了简单的拍照功能 演示地址 bingxl.cn/webrtc.html 代码 <! ...

  2. 远程登陆服务器(window系统)

    1,打开命令输入框: 快捷键:win+R 2.输入命令:mstsc 3.输入你的IP地址和用户名(一般为administrator) 4.输入密码

  3. OnDeserializedAttribute 不能作用于 Xml Serialization 上

    在做测试的时候习惯用xml serialization观察结果.想当然的认为OnDeserialized Attribute 可以同样的使用,但是其实Xml Serialization 并没有实现相对 ...

  4. Ubuntu 16.10 安装mysql

    打开终端 sudo apt update 完成后 sudo apt install mysql-server 中间会提示设置root 账户的密码 有的文章提到 还要 install mysql-cli ...

  5. eclipse 中 添加 tomcat后,启动访问时出现404

    1.切换到 server view. 2.双击出问题的 Server,出现如下页面. 3.选中Server,右键,点击选项卡的 Publish,就能进行编辑. 4.Server path 选中第二项: ...

  6. 我的ORM框架

    任何系统的基础,都可以算是各种数据的增删改查(CRUD).最早操作数据是直接在代码里写SQL语句,后来出现了各种ORM框架.C#下的ORM框架有很多,如微软自己的Entity Framework.第三 ...

  7. Node.js-ReferenceError: _filename is not defined

    简直不要被坑得太惨!!!你能?看出来这前面是两根下划线!两根下划线!两根下划线!太尴尬了~找了半天原因居然是这个!

  8. Leetcode back(215) to be continue

    solution discussion https://leetcode.com/problems/kth-largest-element-in-an-array/description/ -- 21 ...

  9. 在写EF 时把时间格式化的做法

    SELECT COUNT(l.LogSeq), date_format(l.CreateDate,'%Y-%m') CreateDateByMonth FROM LOL l WHERE l.Creat ...

  10. NYOJ(325)+NYOJ(456),01背包

    题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=325 http://acm.nyist.net/JudgeOnline/problem. ...