Python 3.x vs Python2.x
1 . New Division Functionality
statement fumction
>>> 1 / 2 # integer truncation (Python 2.X)
0
>>> 1.0 / 2.0 # returns real quotient (Python 3.x)
0.5
2.PRINT
Python2.x Python3.x
print 'hello world' print('hello world')
3.Range Function
In Python3.x we get a new option for range function. We can extract
the first term, last term and rest of the list separately. This option
was not available in Python2.x. We had to write separate code to extract
these values.
(a, *rest, b) = range(5)
print (a)
0
print(b)
4
print(rest)
[1, 2, 3]
This code section will generate a syntax error in Python2.x.
4.Not Equal To
‘<>’ symbol used in Python2.x to represent not equal to is no
longer available in Python3.x. If we try it it will generate a syntax
error. The symbol ‘!=’ is used instead, which was available in Python2.x
along with ‘<>’.
0 comments:
Post a Comment