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

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.

主站蜘蛛池模板: 门头沟区| 元朗区| 财经| 含山县| 维西| 廉江市| 东安县| 益阳市| 天长市| 中西区| 舟山市| 涿州市| 白玉县| 泰州市| 微博| 盐津县| 胶南市| 巧家县| 伊通| 定陶县| 武清区| 慈溪市| 綦江县| 道真| 泗阳县| 洛浦县| 盐山县| 左云县| 启东市| 广元市| 广平县| 乌拉特后旗| 蒲江县| 沙洋县| 宁远县| 湖州市| 靖州| 陕西省| 威远县| 新乡县| 台北县|