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 ...
随机推荐
- Aspose.Cells导入导出execl
插件:Aspose.Cells 没有安装office插件也能使用: 导出:不能使用ajax异步· /// <summary> /// 导出试题 /// </summary> / ...
- golang and mogodb
1.golang的mogodb包下载:http://gopkg.in/mgo.v2 http://gopkg.in/mgo.v2/bson 2.golang的mongodb操作(mgo):htt ...
- js弹出页面
建立一个HTML文件,输入以下代码就能弹出页面 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- jeecg3.8在子表页面中使用WebUploader组件
bcAbout-update.jsp改动如下: 因为默认子表的上传组件不能回显,所以改造成WebUploader 1.在更新页面注销掉生成代码 <%--<script type=" ...
- 如何快速定位JVM中消耗CPU最多的线程?
第一步.先找出Java的进程PID ps -ef | grep 进程名关键字 这里假设找到的PID是:12345 第二步.找出该进程内最消耗CPU的线程 top -Hp log4x R :11.7 ...
- mysql-查询(DQL)
+ 注释:mysql中的+号只有一个作用,就是运算符,没有连接字符串的作用,连接字符串用concat. ;两个操作数都是数值型,则做加法运算. ; :只要其中有一个时字符型,则会试图将字符转换为数值型 ...
- 配置Slf4j依赖,桥接各种多个日志组件(排除commons-logging依赖的影响)
由于各个jar组件使用的日志框架不一样,实际项目中可能会引入多个jar,通常使用的日志框架有 commons-logging log4j 若同一个项目引入多个日志组件,那么Slf4j组件会有不能捕捉到 ...
- Android 关于apk 打包后的地图定位和导航失败的问题
项目中,使用了高德地图定位,调试的debug包定位完全没有问题,但是签名打包后,却始终无法定位,发现是测试环境下的SHA1码和签名发布版的SHA1码是不同的. 所以我们需要获取发布版的SHA1码: 方 ...
- 【CSS】等高布局
1. 负margin: margin-bottom:-3000px; padding-bottom:3000px; 再配合父标签的overflow:hidden属性即可实现高度自动相等的效果. ...
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...