python2和python3中str,bytes区别
python2中,有basestring、str、bytes、unicode四种类型
其中str == bytes ,basestring = (str,unicode)
>>> isinstance('s',str)
True
>>> isinstance('s',bytes)
True
>>> isinstance('s',unicode)
False
>>> isinstance('s'.decode(),unicode)
True
>>> isinstance('s'.decode(),basestring)
True
>>> isinstance('s',basestring)
True
python3中,有str和bytes类型
>>> isinstance('s',str)
True
>>> isinstance('s',bytes)
False
>>> isinstance('s',unicode)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'unicode' is not defined
>>> isinstance(b's',bytes)
True
>>> isinstance('s',basestring)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'basestring' is not defined
python2和python3中str,bytes区别的更多相关文章
- python2和python3中range的区别
参考自 python2和python3中的range区别 - CSDN博客 http://blog.csdn.net/xiexingshishu/article/details/48581379 py ...
- python2 与python3中最大的区别(编码问题bytes&str
1,在python2.x 中是不区分bytes和str类型的,在python3中bytes和str中是区分开的,str的所有操作bytes都支持 python2 中 >>> s = ...
- Python2与python3中字符串的区别
Python2 在python中包含两种字符串类型:str和unicode,str并不是完全意义上的字符串,其实是由unicode经过编码(encode)后的字节组成的字节字符串,而unicode则是 ...
- python2与python3中除法的区别
python2中的除法 >>>1/2 0 即一个整数(无小数部分的数)被另外一个整数除,计算结果的小数部分被截除了,只留下了整数部分 有时候,这个功能比较有用,譬如在做一些需要取位数 ...
- python2和python3中的range区别
python2中的range返回的是一个列表 python3中的range返回的是一个迭代值 for i in range(1,10)在python2和python3中都可以使用,但是要生成1-10的 ...
- [Python3 填坑] 012 字典的遍历在 Python2 与 Python3 中区别
目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 Python2 中字典的遍历 2.2 Python3 中字典的遍历 2.3 结论 1. print( 坑的信息 ) 挖坑时间:2019/ ...
- Python2和Python3的一些语法区别
Python2和Python3的一些语法区别 python 1.print 在版本2的使用方法是: print 'this is version 2 也可以是 print('this is versi ...
- Python2与Python3字符编码的区别
目录 字符编码应用之Python(掌握) 执行Python程序的三个阶段 Python2与Python3字符串类型的区别(了解) Python2 str类型 Unicode类型 Python3 字符编 ...
- day008 字符编码之 字符编码 、Python2和Python3字符编码的区别
计算机基础(掌握) 启动应用程序的流程 双击qq 操作系统接受指令然后把该操作转化为0和1发送给CPU CPU接受指令然后把指令发送给内存 内存接受指令把指令发送给硬盘获取数据 qq在内存中运行 文本 ...
随机推荐
- "com.android.ide.s.ProcessException:Process 'cand 'C:\Program Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2"
使用Android Studio 出现该问题: "com.android.ide.common.process.ProcessException: org.gradle.process.in ...
- Hibernate原生SQL查询数据转换为HQL查询数据方法
HQL形式:(构造方法不支持timestamp类型) public List<Device> queryByMatherBoardId(String matherBoardId) { St ...
- iOS 中 JSON 数据交换格式
JSON (JavaScript Object Notation)是一种轻量级的数据交换格式. JSON 的详细教程,能够參见 JSON 中国:http://www.json.org.cn/ ...
- 重载delete时的那点事
重载delete时的那点事 C++的异常处理机制就会自动用与被使用 的operator new匹配的operator delete来释放内存(补充一点:在operator new中抛出异常不会导致这样 ...
- 解决oracle和plsql乱码问题
oracle 10g装上后,建了个表写入中文数据,发现通过工具DbVisualizer 6.5 写入/读取中文都正常,就sqlplus和PL/SQL Developer不正常. 初步怀疑是DbVisu ...
- shader学习之路(1)- half lambert
在学习这个shader之前先提个经常使用概念.即光照模型.LightModel(光照模型)即是对于物体怎么对打在其上的光做出视觉反应的数学模型.意即表达物体对光反应产生的视觉效果与入射光.物体表面属性 ...
- struts2+jquery验证注冊用户是否存在
注冊界面 register.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&q ...
- ionicframework(一)
官方网站 http://ionicframework.com 然后在Get Start里面可以了解到,安装Ionic需要安装 Node.js. 文件来源 http://www.tuicool.c ...
- 【Spring实战】—— 6 内部Bean
本篇文章讲解了Spring的通过内部Bean设置Bean的属性. 类似内部类,内部Bean与普通的Bean关联不同的是: 1 普通的Bean,在其他的Bean实例引用时,都引用同一个实例. 2 内部B ...
- python能够执行,但编译第三包遇到 python.h no such file or directory
python能够执行,但编译第三包遇到 python.h no such file or directory 这个问题是由于没有安装python-devel, 安装此包就能够解决次问题,在Linux下 ...