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

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.

主站蜘蛛池模板: 灵璧县| 穆棱市| 北票市| 嘉黎县| 石阡县| 辉县市| 广宁县| 大庆市| 丰原市| 博罗县| 镇平县| 拜城县| 五华县| 高陵县| 菏泽市| 镇宁| 望奎县| 乐至县| 三都| 教育| 贺州市| 德庆县| 浪卡子县| 建德市| 清流县| 田阳县| 习水县| 且末县| 若羌县| 米泉市| 阿勒泰市| 灵武市| 来安县| 青岛市| 东方市| 浦北县| 巴里| 北碚区| 湖南省| 来宾市| 南汇区|