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

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.

主站蜘蛛池模板: 老河口市| 芦溪县| 方山县| 稻城县| 汉寿县| 溆浦县| 潜江市| 枞阳县| 民勤县| 海晏县| 綦江县| 玉环县| 上饶县| 邹平县| 扬州市| 阳城县| 西华县| 乌拉特中旗| 鲁山县| 海淀区| 永仁县| 万荣县| 泊头市| 禹城市| 水城县| 刚察县| 陕西省| 密山市| 湘乡市| 济阳县| 云安县| 临潭县| 秦皇岛市| 塔河县| 巢湖市| 乌拉特后旗| 乡宁县| 宁国市| 家居| 拜城县| 灵武市|