官网说明:Python 2 or 3区别

简介: 官网说明:Python 2 or 3区别

In summary : Python 2.x is legacy, Python 3.x is the present and future of the language

  1. Python 3.0 was released in2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of

  2. extended support for this end-of-life release. The 2.x branch will see no new major releases after that. 3.x is

  3. under active development and has already seen over five years of stable releases, including version 3.3in2012,

  4. 3.4in2014, and3.5in2015. This means that all recent standard library improvements, for example, are only

  5. available by default in Python 3.x.

  6. Guido van Rossum (the original creator of the Python language) decided to clean up Python 2.x properly,
  7. with less regard for backwards compatibility than is the case for new releases in the 2.x range.
  8. The most drastic improvement is the better Unicode support (withall text strings being Unicode by default) as well as saner bytes/Unicode separation.

  9. Besides, several aspects of the core language (such asprintandexec being statements,
  10. integers using floor division) have been adjusted to be easier for newcomers to learn and to be more consistent with the rest of the language,
  11. and old cruft has been removed (for example, all classes are now new-style, "range()" returns a memory efficient iterable,
  12. not a listasin2.x).


py2与3的详细区别

  • PRINT IS A FUNCTION

   The statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old statement (PEP 3105). Examples:

  1. Old: print"The answer is", 2*2
  2. New: print("The answer is", 2*2)
  3. Old: print x, # Trailing comma suppresses newline 【不换行】
  4. New: print(x, end=" ") # Appends a space instead of a newline 【不换行】
  5. Old: print# Prints a newline 【换行】
  6. New: print() # You must call the function!【换行】
  7. Old: print >>sys.stderr, "fatal error"
  8. New: print("fatal error", file=sys.stderr)【标准错误】
  9. Old: print (x, y) # prints repr((x, y))
  10. New: print((x, y)) # Not the same as print(x, y)!


  • You can also customize the separator between items[定制分隔符], e.g.:
  1. print("There are <", 2**32, "> possibilities!", sep="")


  • ALL IS UNICODE NOW
  1. 从此不再为讨厌的字符编码而烦恼


  • 还可以这样玩: (A,*REST,B)=RANGE(5)
  1. >>> a,*rest,b = range(5)
  2. >>> a,rest,b
  3. (0, [1, 2, 3], 4)


  • 某些库改名了

Old Name[pyton2]

New Name[pyton3]

_winreg

winreg

ConfigParser

configparser

copy_reg

copyreg

Queue

queue

SocketServer

socketserver

markupbase

_markupbase

repr

reprlib

test.test_support

test.support

 


相关文章
|
15天前
|
存储 Java 索引
(Python基础)新时代语言!一起学习Python吧!(二):字符编码由来;Python字符串、字符串格式化;list集合和tuple元组区别
字符编码 我们要清楚,计算机最开始的表达都是由二进制而来 我们要想通过二进制来表示我们熟知的字符看看以下的变化 例如: 1 的二进制编码为 0000 0001 我们通过A这个字符,让其在计算机内部存储(现如今,A 字符在地址通常表示为65) 现在拿A举例: 在计算机内部 A字符,它本身表示为 65这个数,在计算机底层会转为二进制码 也意味着A字符在底层表示为 1000001 通过这样的字符表示进行转换,逐步发展为拥有127个字符的编码存储到计算机中,这个编码表也被称为ASCII编码。 但随时代变迁,ASCII编码逐渐暴露短板,全球有上百种语言,光是ASCII编码并不能够满足需求
84 3
|
6月前
|
Python
[oeasy]python086方法_method_函数_function_区别
本文详细解析了Python中方法(method)与函数(function)的区别。通过回顾列表操作如`append`,以及随机模块的使用,介绍了方法作为类的成员需要通过实例调用的特点。对比内建函数如`print`和`input`,它们无需对象即可直接调用。总结指出方法需基于对象调用且包含`self`参数,而函数独立存在无需`self`。最后提供了学习资源链接,方便进一步探索。
133 17
|
11月前
|
存储 开发者 Python
Python 中的数据结构与其他编程语言数据结构的区别
不同编程语言都有其设计理念和应用场景,开发者需要根据具体需求和语言特点来选择合适的数据结构
268 55
|
存储 大数据 数据处理
Python 中的列表推导式与生成器:特性、用途与区别
Python 中的列表推导式与生成器:特性、用途与区别
163 2
|
存储 C语言 Python
解密 Python 的变量和对象,它们之间有什么区别和联系呢?
解密 Python 的变量和对象,它们之间有什么区别和联系呢?
201 2
|
存储 Python
Python中类方法、实例方法与静态方法的区别
这三种方法的正确使用可以使代码更加清晰、组织良好并且易于理解,从而有效地支持软件开发的面向对象编程范式。
349 1
|
Python
全网最适合入门的面向对象编程教程:Python函数方法与接口-函数与方法的区别和lamda匿名函数
【9月更文挑战第15天】在 Python 中,函数与方法有所区别:函数是独立的代码块,可通过函数名直接调用,不依赖特定类或对象;方法则是与类或对象关联的函数,通常在类内部定义并通过对象调用。Lambda 函数是一种简洁的匿名函数定义方式,常用于简单的操作或作为其他函数的参数。根据需求,可选择使用函数、方法或 lambda 函数来实现代码逻辑。
150 7
|
机器学习/深度学习 人工智能 安全
python和Java的区别以及特性
Python:适合快速开发、易于维护、学习成本低、灵活高效。如果你需要快速上手,写脚本、数据处理、做点机器学习,Python就是你的首选。 Java:适合大型项目、企业级应用,性能要求较高的场景。它类型安全、跨平台能力强,而且有丰富的生态,适合更复杂和规模化的开发。
512 3
|
机器学习/深度学习 缓存 Linux
python环境学习:pip介绍,pip 和 conda的区别和联系。哪个更好使用?pip创建虚拟环境并解释venv模块,pip的常用命令,conda的常用命令。
本文介绍了Python的包管理工具pip和环境管理器conda的区别与联系。pip主要用于安装和管理Python包,而conda不仅管理Python包,还能管理其他语言的包,并提供强大的环境管理功能。文章还讨论了pip创建虚拟环境的方法,以及pip和conda的常用命令。作者推荐使用conda安装科学计算和数据分析包,而pip则用于安装无法通过conda获取的包。
1280 0
|
存储 测试技术 Python
Python 数组和列表有什么区别?
【8月更文挑战第29天】
2939 4

热门文章

最新文章

推荐镜像

更多