官术网_书友最值得收藏!

Key differences between Python 2.7 and Python 3

Here are some main differences between Python 2.x and Python 3:

  • Print: In Python 2, print is a statement. So, there is no need to wrap the text in parentheses for printing. But in Python 3 print is a function. So, you have to pass the string you need to print to the function in parentheses.
  • Integer pision: Python 2 considers numbers without any digits after the decimal point as integers, which may lead to some unexpected results during pision.
  • List comprehension loop variables leak: In Python 2, giving the variable that is iterated over in a list comprehension leaks the variable into surrounding scope, this list comprehension loop variable leak bug has been fixed in Python 3.
  • Unicode strings: Python 2 requires you to mark the unicode string explicitly with the u prefix. But, Python 3 stores strings as unicode by default.
  • Raising exceptions: Python 3 requires different syntax for raising exceptions.

The progression from Python 2.x to Python 3.x is happening slowly, but it is underway. It is good to be mindful that there are material differences between Python 2.x and Python 3 as you may need to deal with code that is written in the version with which you are less familiar.

主站蜘蛛池模板: 明光市| 朔州市| 临江市| 民勤县| 浑源县| 凌海市| 婺源县| 喜德县| 疏勒县| 武强县| 安图县| 辉县市| 亚东县| 库尔勒市| 阿瓦提县| 昭觉县| 四川省| 丹江口市| 武川县| 务川| 武山县| 乌兰县| 壤塘县| 揭阳市| 井冈山市| 略阳县| 鄱阳县| 沾益县| 长乐市| 丰台区| 曲靖市| 山东省| 田阳县| 扎兰屯市| 华宁县| 永宁县| 和平区| 黎城县| 江都市| 钟祥市| 大关县|