Python之路Python3【第零篇】Python2 & Python3区别持续更新~
2016-05-13 22:18
489 查看
def print(self, *args, sep=' ', end='\n', file=None): # known special case of print """ print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream. """ pass
Python2中print是一个语句,只需要向吧输出的放在print关键字后面就可以输出。
Python3中从上面的代码中可以看出他现在是一个函数,就像其他函数一样,print()需要您将要输出的内容作为参数传给他。
Unicode字符串
Python 2有两种字符串类型:Unicode字符串和非Unicode字符串。Python 3只有一种类型:Unicode字符串(Unicode strings)。1、Python2里的Unicode字符串在Python3里也是普通的字符串,因为在Python里字符串总是Unicode形式的
所以你就可以用下面的方式命名变量了,但是不要这样使用~~
帅哥 = '罗天帅' print(帅哥)
2、Unicode原始字符串(raw string),使用这种字符串,Python不会自动转移反斜线“\”也会被替换为普通的字符串,因为在Python3里所有的原始字符串也都是Unicode编码的
Python 2有两种字符串类型:Unicode字符串和非Unicode字符串。Python 3只有一种类型:Unicode字符串(Unicode strings)。
3、Python 2有两个全局函数可以把对象强制转换成字符串:
unicode()把对象转换成Unicode字符串,还有
str()把对象转换为非Unicode字符串。Python 3只有一种字符串类型,Unicode字符串,所以
str()函数即可完成所有的功能。(
unicode()函数在Python 3里不再存在了。)
相关文章推荐
- 100. Same Tree [easy] (Python)
- Python lambda(匿名函数)函数总结
- Python装饰器学习(九步入门)
- python string.atof( )函数
- Python闲谈(一)mgrid慢放
- python urllib 和urllib2的区别
- Python标准输出重定向
- Windows下打包Python的exe可执行文件
- Python之路—Day1作业
- python3.x输出文件最后几行
- pip install jupyter UnicodeDecodeError | ipython notebook 安装失败
- Python――How to use python pip/pur
- 如何上传python
- 如何上传python
- 最全Python爬虫总结
- Beautiful Soup 4库--python2.x(学习日记)
- Python实现欧拉计划23题
- Python之路—Day1
- 如何优雅的用Python玩转语音聊天机器人
- leetcode(8),Majority Element(python)