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

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.

主站蜘蛛池模板: 渭源县| 淳安县| 自贡市| 溧水县| 茌平县| 永丰县| 如东县| 长治市| 磴口县| 哈密市| 张家川| 高淳县| 涡阳县| 玛多县| 万全县| 山丹县| 仙桃市| 金湖县| 隆尧县| 囊谦县| 响水县| 德令哈市| 资阳市| 明光市| 新郑市| 松江区| 曲阜市| 灵璧县| 双流县| 彩票| 洪江市| 新绛县| 丹寨县| 阿拉善左旗| 精河县| 灌云县| 铁力市| 郯城县| 阜南县| 纳雍县| 牟定县|