目录

python2.7与python3的区别_Python-2.7与Python-3.7区别

目录

python2.7与python3的区别_Python 2.7与Python 3.7区别

今天,我将带大家看看Python 2.7与Python 3.7这两个版本区别。

https://i-blog.csdnimg.cn/blog_migrate/d2ed2c395fd382b947792241a898c764.jpeg

区别一:print语法使用

Python2.7 print语法使用 »> print “Hello Python”

Python3.7 print语法使用 »> print(“Hello Python”)

例子:在Python 3.7.0使用双引号触发SyntaxError异常机制 提示Did you mean print(“Hello Python3.7”)

https://i-blog.csdnimg.cn/blog_migrate/b43a556790df7e63c943a0c6df786175.png

print 换行和不换行区别

python 2.7 print 不换行使用",“即可

https://i-blog.csdnimg.cn/blog_migrate/2da7ceab4b9a92adc5a9bbff89f03523.png

python 3.7 print 不换行使用end=”"

https://i-blog.csdnimg.cn/blog_migrate/63746824138efe6644ab0f19e7b649e7.png

区别二: raw_input()和input()

Python 2.7 raw_input() input() 都存在 可使用 raw_input()接收字符串string input()接收数字int /flot.

Python 3.7 raw_input()不存在 仅存在input() 两者合并 接收任意格式 返回string

https://i-blog.csdnimg.cn/blog_migrate/e9f8168e0c7463c4ce1a71987ce62466.png

https://i-blog.csdnimg.cn/blog_migrate/aa73195b49de129d0de2f02da85397c0.png

区别三: 函数cmp()

python 2.7 cmp(x,y)函数用于比较2个对象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1

python3.7 cmp()已经不存在了,如果你需要实现比较功能,需要引入 operator 模块,适合任何对象

import operator»> operator.eq(‘hello’, ’name’);False»> operator.eq(‘hello’, ‘hello’);True

区别四:string 字母 大小写字符串

string.letters:包含所有字母(大写或小写)的字符串

Python 3.0中,string.ascii_letters.

以上就是Python 2.7与Python 3.7区别的详细内容,更多请关注php中文网其它相关文章!

https://i-blog.csdnimg.cn/blog_migrate/f68f2add0b68e4f9810432fce46917b7.jpeg

本文转载于:博客园,如有侵犯,请联系a@php.cn删除