官网说明: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

 


目录
相关文章
|
2月前
|
存储 Python
Python中encode和encoding的区别
Python中encode和encoding的区别
36 0
|
2月前
|
存储 数据库 索引
Python新手常见问题一:列表、元组、集合、字典区别是什么?
本文针对Python编程新手常遇到的问题,详细阐述了列表(List)、元组(Tuple)、集合(Set)和字典(Dictionary)这四种数据结构的核心区别。列表是一种有序且可变的数据序列,允许元素重复;元组同样有序但不可变,其内容一旦创建就不能修改;集合是无序、不重复的元素集,强调唯一性,主要用于数学意义上的集合操作;而字典则是键值对的映射容器,其中键必须唯一,而值可以任意,它提供了一种通过键查找对应值的有效方式。通过对这些基本概念和特性的对比讲解,旨在帮助初学者更好地理解并运用这些数据类型来解决实际编程问题。
38 1
|
6天前
|
Python
在Python Web开发过程中:`is`和`==`在Python中的区别是什么?
【4月更文挑战第25天】Python的`is`与`==`用于比较。`is`检查对象是否相同(内存地址一致),而`==`检查值是否相等。例如,`a = [1, 2, 3]`,`b = a`,`c = [1, 2, 3]`,则`a is b`和`a == b`均为True,但`a is c`为False,`a == c`为True,因`a`和`b`引用同一对象,而`a`和`c`值虽等但对象不同。
7 1
|
28天前
|
人工智能 机器人 测试技术
【Python】Python迭代器与生成器的区别(详细讲解)
【Python】Python迭代器与生成器的区别(详细讲解)
【Python】Python迭代器与生成器的区别(详细讲解)
|
2月前
|
Python
在Python Web开发过程中:网络与并发,解释一下在Web开发中会遇到的长连接与短连接的区别。
Python Web开发中的长连接和短连接影响网络性能。长连接保持开放状态,允许多次数据交换,减少建立/释放开销,适合频繁交互。短连接每次请求新建,简单但高并发时增加开销。长连接利于实时通信,短连接适合HTTP等一次性请求。选择取决于应用需求、资源管理、可靠性和并发处理能力。
12 2
|
2月前
|
算法 开发者 Python
【Python 基础扫盲 】self参数、__init__方法和.__str__方法的用处和区别?
【Python 基础扫盲 】self参数、__init__方法和.__str__方法的用处和区别?
20 0
|
2月前
|
Python
请简述Python中的深拷贝和浅拷贝的区别?并举例说明。
【2月更文挑战第25天】【2月更文挑战第84篇】请简述Python中的深拷贝和浅拷贝的区别?并举例说明。
|
2月前
|
Python
请解释Python中的迭代器和生成器的区别?并分别举例说明。
【2月更文挑战第24天】【2月更文挑战第80篇】请解释Python中的迭代器和生成器的区别?并分别举例说明。
|
2月前
|
存储 Python
请简述Python中的列表、元组和字典的区别?
请简述Python中的列表、元组和字典的区别?
12 1
|
2月前
|
Python
请解释Python中的全局变量和局部变量有什么区别?
请解释Python中的全局变量和局部变量有什么区别?
17 2