The difference between Python 2.7 and Python 3.7

little bottle
Release: 2019-04-08 10:47:43
forward
4913 people have browsed it

Today, I will show you the differences between the two versions of Python 2.7 and Python 3.7.

The difference between Python 2.7 and Python 3.7

Difference 1: print syntax is used

Python2.7 print syntax is used >>> print "Hello Python"

Python3.7 Print syntax usage >>> print("Hello Python")

Example: Using double quotes to trigger the SyntaxError exception mechanism in Python 3.7.0 prompts Did you mean print("Hello Python3.7")

The difference between Python 2.7 and Python 3.7

The difference between print and no line break

python 2.7 Use "," to print without line break

The difference between Python 2.7 and Python 3.7

python 3.7 print without line breaks uses end=""

The difference between Python 2.7 and Python 3.7

Difference 2: raw_input() and input()

Python 2.7 raw_input() and input() both exist and can be used. raw_input() receives a string. input() receives a number int /flot.

Python 3.7 raw_input() does not exist. Only input() exists. The two are combined and receive any Format returns string

The difference between Python 2.7 and Python 3.7

The difference between Python 2.7 and Python 3.7

Difference three: function cmp()

python 2.7 cmp(x,y) function is used For comparing two objects, if x y returns 1

python3.7 cmp() no longer exists, if you need To implement the comparison function, you need to introduce the operator module, which is suitable for any object

>>> import operator>>> operator.eq('hello', 'name');False>>> operator.eq('hello', 'hello');True

Difference four: string letter case string

string.letters: a string containing all letters (uppercase or lowercase)

In Python 3.0, string.ascii_letters.

[Recommended course: Python column course]

The above is the detailed content of The difference between Python 2.7 and Python 3.7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template