首页 存档 技术 查看内容

Python到python的编译器允许你在老版本中使用Python 3.6的一些功能

2018-3-30 13:00 |来自: 互联网 381 0

摘要: Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发。 Py-backwards Python到python的编译器允许你在老版本中使用Python 3.6的一些功能,你可以通过这个在线样例(https://py-backwards.herokuapp.com ...

Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发。

Py-backwards

Python到python的编译器允许你在老版本中使用Python 3.6的一些功能,你可以通过这个在线样例(https://py-backwards.herokuapp.com/)试用它。

需要Python 3.3 来运行,可以向下编译至Python 2.7。

支持的特性

目标 3.5:

  • 格式化字符串常量:如 f"hi {x}" (https://docs.python.org/3/whatsnew/3.6.html#pep-498-formatted-string-literals)

  • 变量注释:如 x: int = 10 和 x: int (https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep526)

  • 数字常量中的下划线:如 1_000_000(自动进行) (https://docs.python.org/3/whatsnew/3.6.html#pep-515-underscores-in-numeric-literals)

目标 3.4:

  • 带星标的(元组)解包:如 [*range(1, 5), *range(10, 15)] 和 print(*[1, 2], 3, *[4, 5]) (https://docs.python.org/3/whatsnew/3.5.html#pep-448-additional-unpacking-generalizations)

  • 字典解包:如 {1: 2, **{3: 4}} (https://docs.python.org/3/whatsnew/3.5.html#pep-448-additional-unpacking-generalizations)

目标 3.3:

  • 导入pathlib2而不是pathlib (https://pypi.python.org/pypi/pathlib2/)

目标 3.2:

  • yield from (https://docs.python.org/3/whatsnew/3.3.html#pep-380)

  • return from generator (https://docs.python.org/3/whatsnew/3.3.html#pep-380)

目标 2.7:

  • 函数注释:如 def fn(a: int) -

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部