Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python 2 or Python 3? - (Finally) Understanding...

yyyyyyyan
October 21, 2018

Python 2 or Python 3? - (Finally) Understanding the differences between the two main versions of the language

yyyyyyyan

October 21, 2018
Tweet

More Decks by yyyyyyyan

Other Decks in Programming

Transcript

  1. 8 Python 2 or Python 3? (Finally) Understanding the differences

    between the two main versions of the language
  2. >>> print 'Hello, world!' File "<stdin>", line 1 print 'Hello,

    world!' ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, world!')? Python 3 11
  3. Python 2 >>> input() Hello! Traceback (most recent call last):

    File "<stdin>", line 1, in <module> File "<string>", line 1 Hello! ^ SyntaxError: unexpected EOF while parsing 15
  4. Python 2 >>> range(10**10) Traceback (most recent call last): File

    "<stdin>", line 1, in <module> MemoryError 19
  5. Python 2 >>> xrange(10000**10000) Traceback (most recent call last): File

    "<stdin>", line 1, in <module> OverflowError: Python int too large to convert to C long 23
  6. Python 3 >>> type('Hello, world!') <class 'str'> >>> type(u'Hello, world!')

    <class 'str'> >>> type(b'Hello, world!') <class 'bytes'> 37
  7. 47 Python 2 >>> foo = MyClass() >>> foo <

    'a' True >>> foo < 1 True >>> foo < [] True
  8. 48 Python 2 >>> 999999999 < 'a' True >>> 999999999

    < [] True >>> 999999999.99 < [] True
  9. 49 Python 2 >>> ' ' > [] True >>>

    'str' > 'list' True
  10. 50 Python 3 >>> ' ' > [] Traceback (most

    recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'str' and 'list'
  11. 52 Python 3 >>> while True: ... print('hello') ... print('bye')

    File "<stdin>", line 3 print('bye') ^ TabError: inconsistent use of tabs and spaces in indentation
  12. 56 2014 - Python 2 78% X 22% Python 3

    2016 - Python 2 60% X 40% Python 3
  13. 57 2014 - Python 2 78% X 22% Python 3

    2016 - Python 2 60% X 40% Python 3 2017 - Python 2 25% X 75% Python 3