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 ...
随机推荐
- Redis入门--(二)Redis的安装
1.建议安装在Linux服务器上来运行测试的
- css3实现iPhone滑动解锁
该效果的主要实现思路是给文字添加渐变的背景,然后对背景进行裁剪,按文字裁剪(目前只有webkit内核浏览器支持该属性),最后给背景添加动画,即改变背景的位置,背景动画效果如下(GIF录制时有卡顿,代码 ...
- eclipse:maven工程下显示不出文件,但系统存在,可能是这个原因
- Ajax使用 初始化数据 + mvc
2017-3-16 mvc+jquery+easyUI做项目 <input type="text" id="txtSTQty" name="tx ...
- 如何将centos7自带的firewall防火墙更换为iptables防火墙
用惯了centos6的iptables防火墙,对firewall太无感了,那么如何改回原来熟悉的iptables防火墙呢? 1.关闭firewall防火墙 [root@centos7 html]# s ...
- PHP使用MySQL报no such file or directory
原因是没有连接数据库.加上下面代码: $link = mysql_connect(DB_HOST,DB_USER,DB_PWD);mysql_select_db(DB_NAME) or die('Co ...
- Element-ui安装与使用(网站快速成型工具)
我之所以将Element归类为Vue.js,其主要原因是Element是(饿了么团队)基于MVVM框架Vue开源出来的一套前端ui组件.我最爱的就是它的布局容器!!! 下面进入正题: 1.Elemen ...
- QT学习之QScript
QT中有解析Json的一个类叫QScript.貌似还有一个QJson,但听说解析的方便性不如QScript,具体没有深入探究,这里仅简单记录一下QScript的使用. 首先,主要使用到的类有QScri ...
- 制作URL以GET方式提交的简单加密程序
首先我们用到的是 DESCryptoServiceProvider 类 对此微软给出的解释是 定义访问数据加密标准 (DES) 算法的加密服务提供程序 (CSP) 版本的包装对象.无法继承此类. 接下 ...
- php简单开启gzip压缩方法(zlib.output_compression)
网上的教程基本是你抄我来我抄他,不外乎加头加尾或者自构函数两种写法.实际上每个php页面都要去加代码——当然也可以include引用,不过总显得略微麻烦 一般而言,页面文件开启gzip压缩以后,其 ...