I started learning Python this week, because the books I read are based on Python 2.x, and I installed Python 3.1, so many of the places written in the book don't apply to Python 3.1. I specifically searched on Google 3 The difference between .x and 2.x. Hereby record in your own space, in case you need to find it later, you can also share it with friends who want to learn Python.
Performance
Py3.0 runs the pystone benchmark 30% slower than Py2.5. Guido believes that Py3.0 has a lot of optimization space, which can be used in string and shaping operations.
In order to achieve good optimization results.
Py3.1 performance is 15% slower than Py2.5, and there is a lot of room for improvement.
2. Coding
The Py3.X source file uses utf-8 encoding by default, which makes the following code legal:
>>> China = 'china'
>>>print(China)
China
3. Grammar
1) Removed <>, all changed to use!=
2) Remove ``, all use repr()
3) Add keywords as and as, and True, False, None
4) Integer division returns a floating point number. To get the integer result, please use //
5) Join the nonlocal statement. Use noclocal x to directly assign peripheral (non-global) variables
6) Remove the print statement and add the print() function to achieve the same function. The same is the exec statement, has been changed to exec () function
E.g:
2.X: print "The answer is", 2*2
3.X: print("The answer is", 2*2)
2.X: print x, # Use a comma to end the line break
3.X: print(x, end=" ") # Replace the line with a space substitution
2.X: print # output new line
3.X: print() # output new line
2.X: print >>sys.stderr, "fatal error"
3.X: print("fatal error", file=sys.stderr)
2.X: print (x, y) # output repr((x, y))
3.X: print((x, y)) # is different from print(x, y)!
7) Changed the behavior of the sequence operator, for example x 8) The input function changed, deleted raw_input, replaced with input:
2.X:guess = int(raw_input('Enter an integer : ')) # How to read keyboard input
3.X:guess = int(input('Enter an integer : ')), throws typeerror when x and y types don't match, instead of returning immediately >
9) Remove the tuple parameter unpacking. Can't define a function like def(a, (b, c)):pass
10) The new octal word variable, modified the oct() function accordingly.
2.X is as follows:
>>> 0666
438
>>> oct(438)
'0666'
3.X like this:
>>> 0666
SyntaxError: invalid token (, line 1)
>>> 0o666
438
>>> oct(438)
'0o666'
11) Added binary literal and bin() function
>>> bin(438)
'0b110110110'
>>> _438 = '0b110110110'
>>> _438
'0b110110110'
12) Extended iterative unwrapping. In Py3.X, a, b, *rest = seq and *rest, a = seq are legal, only two points are required: rest is list
Objects and seq are iterable.
13) The new super() can no longer pass parameters to super().
>>> class C(object):
Def __init__(self, a):
Print('C', a)
>>> class D(C):
Def __init(self, a):
Super().__init__(a) # Call super() with no arguments
>>> D(8)
C 8
<__main__.D object at 0x00D7ED90>
14) New metaclass syntax:
Class Foo(*bases, **kwds):
Pass
15) Support class decorator. Usage is the same as the function decorator:
>>> def foo(cls_a):
Def print_func(self):
Print('Hello, world!')
Cls_a.print = print_func
Return cls_a
>>> @foo
Class C(object):
Pass
>>> C().print()
Hello, world!
The class decorator can be used to play the big trick of the civet cat for the prince. See PEP 3129 for more
4. String and byte strings
1) Now the string is only a type of str, but it is almost the same as the 2.x version of unicode. #63>
Vacuum Cleaner Dc Dry-Wet Motor
Vacuum Cleaner Dc Dry-Wet Motor,Motor Vacuum Cleaner Robot,Dc Wet Vacuum Cleaner Motor,Dc Dry Vacuum Cleaner Motor
Zhoushan Chenguang Electric Appliance Co., Ltd. , https://www.vacuum-cleaner-motors.com