is和==,encode和decode
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的更多相关文章
- [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 ...
- 【python】python新手必碰到的问题---encode与decode,中文乱码[转]
转自:http://blog.csdn.net/a921800467b/article/details/8579510 为什么会报错“UnicodeEncodeError:'ascii' codec ...
- LeetCode Encode and Decode Strings
原题链接在这里:https://leetcode.com/problems/encode-and-decode-strings/ 题目: Design an algorithm to encode a ...
- Encode and Decode Strings
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...
- encode和decode
Python字符串的encode与decode研究心得乱码问题解决方法 为什么会报错“UnicodeEncodeError: 'ascii' codec can't encode characters ...
- 【python】浅谈encode和decode
对于encode和decode,笔者也是根据自己的理解,有不对的地方还请多多指点. 编码的理解: 1.编码:utf-8,utf-16,gbk,gb2312,gb18030等,编码为了便于理解,可以把它 ...
- 271. Encode and Decode Strings
题目: Design an algorithm to encode a list of strings to a string. The encoded string is then sent ove ...
- [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 ...
- Encode and Decode Strings 解答
Question Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...
- python encode和decode函数说明【转载】
python encode和decode函数说明 字符串编码常用类型:utf-8,gb2312,cp936,gbk等. python中,我们使用decode()和encode()来进行解码和编码 在p ...
随机推荐
- c#-day04学习笔记
面向对象 类与对象: C#的类和对象是用于在程序中模拟现实生活中的事务的 C#中的类是一种数据类型,用来定义对象的类型的 C#的对象是类的实例,是基于[给定数据类型]的具体的一个实例 小结: 类是对象 ...
- golang中并发的相关知识
golang中done channel理解:https://segmentfault.com/a/1190000006261218 golang并发模型之使用Context:https://segme ...
- C# FTPHelper帮助类
网上的FTPHelper类感觉用起来不方便,而且代码的质量也不高,因此自己重新写了一个FTPHelper.此文之前是发布在我的CSDN博客中的,现在转过来. 主要就是借鉴了DbHelper的Creat ...
- jquery常用属性与方法
1..css( )给指定的样式设置样式值: 2..attr(attributeName,value) /.removeAttr(attributeName);给指定的属性设置值 / 清除所有匹配的元素 ...
- WebSocket Demo
HTML 代码: <body> <h1>WebScoket示例</h1> <br /><br /> <input type=" ...
- view 状态动画
stateListAnimator 一.xml配置 方法 res/xml/animate_scale.xml <?xml version="1.0" encoding=&qu ...
- Build 2017 | 今儿来说说火得不行的认知服务吧(内附微软开发者大会在线峰会报名地址)
Everybody,新一期的 Build 2017 大会新技术详谈又来了,今天小编给大家带来了一个既智能又有趣的技术,你一定喜欢!不卖关子了,直奔我们本期的主题: [只需几行代码,就能让任何应用更智能 ...
- jmeter之HTTP信息头管理器
信息头管理器作用: HTTP信息头管理器在Jmeter的使用过程中起着很重要的作用,通常我们在通过Jmeter向服务器发送http请求(get或者post)的时候,往往后端需要一些验证信息,比如说we ...
- April 22 2017 Week 16 Saturday
Fear is an essential part of our survival, it keeps us alert. 恐惧是生存的重要部分,它让我们保持警惕. Fear and pain are ...
- 1923. Scary Politics (timus) (dfs) search
http://acm.timus.ru/problem.aspx?space=1&num=1923 -- timus This is s problem about thd dfs and s ...