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

Introduce syntax and history of Python from 2.4 to 3.6 (PyCon APAC 2018)

Introduce syntax and history of Python from 2.4 to 3.6 (PyCon APAC 2018)

Manabu TERADA

June 01, 2018
Tweet

More Decks by Manabu TERADA

Other Decks in Technology

Transcript

  1. Introduce syntax and Introduce syntax and Introduce syntax and Introduce

    syntax and Introduce syntax and Introduce syntax and history of Python from 2.4 to 3.6 history of Python from 2.4 to 3.6 history of Python from 2.4 to 3.6 history of Python from 2.4 to 3.6 history of Python from 2.4 to 3.6 history of Python from 2.4 to 3.6 - PyCon APAC 2018 Singapore - - PyCon APAC 2018 Singapore - - PyCon APAC 2018 Singapore - - PyCon APAC 2018 Singapore - - PyCon APAC 2018 Singapore - - PyCon APAC 2018 Singapore - 2018-06-01 2018-06-01 2018-06-01 2018-06-01 2018-06-01 2018-06-01 @terapyon @terapyon @terapyon @terapyon @terapyon @terapyon 1 / 38
  2. Self introduction Self introduction Self introduction Self introduction Self introduction

    Self introduction Manabu TERADA Manabu TERADA Manabu TERADA Manabu TERADA Manabu TERADA Manabu TERADA ( 寺田 学) ( 寺田 学) ( 寺田 学) ( 寺田 学) ( 寺田 学) ( 寺田 学) Python engineer Python engineer Python engineer Python engineer Python engineer Python engineer Board Chair of PyCon JP (Japan) Board Chair of PyCon JP (Japan) Board Chair of PyCon JP (Japan) Board Chair of PyCon JP (Japan) Board Chair of PyCon JP (Japan) Board Chair of PyCon JP (Japan) Plone Foundation Ambassador Plone Foundation Ambassador Plone Foundation Ambassador Plone Foundation Ambassador Plone Foundation Ambassador Plone Foundation Ambassador PSF Contributing member PSF Contributing member PSF Contributing member PSF Contributing member PSF Contributing member PSF Contributing member Member of NVDA Japanese Team Member of NVDA Japanese Team Member of NVDA Japanese Team Member of NVDA Japanese Team Member of NVDA Japanese Team Member of NVDA Japanese Team                               2 / 38
  3. Our company Our company Our company Our company Our company

    Our company CMS Communications Inc. CMS Communications Inc. CMS Communications Inc. CMS Communications Inc. CMS Communications Inc. CMS Communications Inc. Our company is CMScom based in Tokyo, Japan Our company is CMScom based in Tokyo, Japan Our company is CMScom based in Tokyo, Japan Our company is CMScom based in Tokyo, Japan Our company is CMScom based in Tokyo, Japan Our company is CMScom based in Tokyo, Japan We use Plone for building web sites We use Plone for building web sites We use Plone for building web sites We use Plone for building web sites We use Plone for building web sites We use Plone for building web sites Universities, Public institutions Universities, Public institutions Universities, Public institutions Universities, Public institutions Universities, Public institutions Universities, Public institutions Engineering companies Engineering companies Engineering companies Engineering companies Engineering companies Engineering companies Supporting education tools Supporting education tools Supporting education tools Supporting education tools Supporting education tools Supporting education tools Plone Plone Plone Plone Plone Plone, , , , , , Pyramid and Open edX Pyramid and Open edX Pyramid and Open edX Pyramid and Open edX Pyramid and Open edX Pyramid and Open edX                               3 / 38
  4. Question Question Question Question Question Question Do you use Do

    you use Do you use Do you use Do you use Do you use Python 2 Python 2 Python 2 Python 2 Python 2 Python 2 or or or or or or Python 3 Python 3 Python 3 Python 3 Python 3 Python 3 5 / 38
  5. Question Question Question Question Question Question Do you Do you

    Do you Do you Do you Do you PREFER PREFER PREFER PREFER PREFER PREFER Python 2 Python 2 Python 2 Python 2 Python 2 Python 2 or or or or or or Python 3 Python 3 Python 3 Python 3 Python 3 Python 3 6 / 38
  6. The history of Python by release date The history of

    Python by release date The history of Python by release date The history of Python by release date The history of Python by release date The history of Python by release date 7 / 38
  7. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version between Python 2.4 and Python between Python 2.4 and Python between Python 2.4 and Python between Python 2.4 and Python between Python 2.4 and Python between Python 2.4 and Python 3.6 3.6 3.6 3.6 3.6 3.6 3.7 3.7 3.7 3.7 3.7 3.7 Picking up major changes of each version Picking up major changes of each version Picking up major changes of each version Picking up major changes of each version Picking up major changes of each version Picking up major changes of each version 8 / 38
  8. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 2.4  (released 2004) Python 2.4  (released 2004) Python 2.4  (released 2004) Python 2.4  (released 2004) Python 2.4  (released 2004) Python 2.4  (released 2004) PEP 218: Built-In Set Objects PEP 218: Built-In Set Objects PEP 218: Built-In Set Objects PEP 218: Built-In Set Objects PEP 218: Built-In Set Objects PEP 218: Built-In Set Objects PEP 289: Generator Expressions PEP 289: Generator Expressions PEP 289: Generator Expressions PEP 289: Generator Expressions PEP 289: Generator Expressions PEP 289: Generator Expressions PEP 318: Decorators for Functions and Methods PEP 318: Decorators for Functions and Methods PEP 318: Decorators for Functions and Methods PEP 318: Decorators for Functions and Methods PEP 318: Decorators for Functions and Methods PEP 318: Decorators for Functions and Methods PEP 322: Reverse Iteration PEP 322: Reverse Iteration PEP 322: Reverse Iteration PEP 322: Reverse Iteration PEP 322: Reverse Iteration PEP 322: Reverse Iteration PEP 328: Multi-line Imports PEP 328: Multi-line Imports PEP 328: Multi-line Imports PEP 328: Multi-line Imports PEP 328: Multi-line Imports PEP 328: Multi-line Imports                               9 / 38
  9. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 2.5 (released 2006) Python 2.5 (released 2006) Python 2.5 (released 2006) Python 2.5 (released 2006) Python 2.5 (released 2006) Python 2.5 (released 2006) PEP 308: Conditional Expressions PEP 308: Conditional Expressions PEP 308: Conditional Expressions PEP 308: Conditional Expressions PEP 308: Conditional Expressions PEP 308: Conditional Expressions PEP 328: Absolute and Relative Imports PEP 328: Absolute and Relative Imports PEP 328: Absolute and Relative Imports PEP 328: Absolute and Relative Imports PEP 328: Absolute and Relative Imports PEP 328: Absolute and Relative Imports PEP 341: Uni ed try/except/ nally PEP 341: Uni ed try/except/ nally PEP 341: Uni ed try/except/ nally PEP 341: Uni ed try/except/ nally PEP 341: Uni ed try/except/ nally PEP 341: Uni ed try/except/ nally New Modules / ElementTree, sqlite3 and more package New Modules / ElementTree, sqlite3 and more package New Modules / ElementTree, sqlite3 and more package New Modules / ElementTree, sqlite3 and more package New Modules / ElementTree, sqlite3 and more package New Modules / ElementTree, sqlite3 and more package                         10 / 38
  10. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 2.6 (released 2008) Python 2.6 (released 2008) Python 2.6 (released 2008) Python 2.6 (released 2008) Python 2.6 (released 2008) Python 2.6 (released 2008) PEP 343: The ‘with’ statement PEP 343: The ‘with’ statement PEP 343: The ‘with’ statement PEP 343: The ‘with’ statement PEP 343: The ‘with’ statement PEP 343: The ‘with’ statement PEP 3101: Advanced String Formatting / PEP 3101: Advanced String Formatting / PEP 3101: Advanced String Formatting / PEP 3101: Advanced String Formatting / PEP 3101: Advanced String Formatting / PEP 3101: Advanced String Formatting / str.format str.format str.format str.format str.format str.format PEP 3110: Exception-Handling Changes/ PEP 3110: Exception-Handling Changes/ PEP 3110: Exception-Handling Changes/ PEP 3110: Exception-Handling Changes/ PEP 3110: Exception-Handling Changes/ PEP 3110: Exception-Handling Changes/ except Exception as e except Exception as e except Exception as e except Exception as e except Exception as e except Exception as e PEP 3119: Abstract Base Classes PEP 3119: Abstract Base Classes PEP 3119: Abstract Base Classes PEP 3119: Abstract Base Classes PEP 3119: Abstract Base Classes PEP 3119: Abstract Base Classes PEP 3129: Class Decorators PEP 3129: Class Decorators PEP 3129: Class Decorators PEP 3129: Class Decorators PEP 3129: Class Decorators PEP 3129: Class Decorators                               11 / 38
  11. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 2.7 (released 2010) Python 2.7 (released 2010) Python 2.7 (released 2010) Python 2.7 (released 2010) Python 2.7 (released 2010) Python 2.7 (released 2010) PEP 372: Adding an Ordered Dictionary to collections PEP 372: Adding an Ordered Dictionary to collections PEP 372: Adding an Ordered Dictionary to collections PEP 372: Adding an Ordered Dictionary to collections PEP 372: Adding an Ordered Dictionary to collections PEP 372: Adding an Ordered Dictionary to collections PEP 378: Format Speci er for Thousands Separator PEP 378: Format Speci er for Thousands Separator PEP 378: Format Speci er for Thousands Separator PEP 378: Format Speci er for Thousands Separator PEP 378: Format Speci er for Thousands Separator PEP 378: Format Speci er for Thousands Separator PEP 389: The argparse Module for Parsing Command Lines PEP 389: The argparse Module for Parsing Command Lines PEP 389: The argparse Module for Parsing Command Lines PEP 389: The argparse Module for Parsing Command Lines PEP 389: The argparse Module for Parsing Command Lines PEP 389: The argparse Module for Parsing Command Lines                   12 / 38
  12. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 3.0 - 3.2 (released 2008) Python 3.0 - 3.2 (released 2008) Python 3.0 - 3.2 (released 2008) Python 3.0 - 3.2 (released 2008) Python 3.0 - 3.2 (released 2008) Python 3.0 - 3.2 (released 2008) PEP 3105: print As a Function PEP 3105: print As a Function PEP 3105: print As a Function PEP 3105: print As a Function PEP 3105: print As a Function PEP 3105: print As a Function PEP 3106: Revamping dict.keys(), .values() and .items() PEP 3106: Revamping dict.keys(), .values() and .items() PEP 3106: Revamping dict.keys(), .values() and .items() PEP 3106: Revamping dict.keys(), .values() and .items() PEP 3106: Revamping dict.keys(), .values() and .items() PEP 3106: Revamping dict.keys(), .values() and .items() PEP 238: Changing the Division Operator/ PEP 238: Changing the Division Operator/ PEP 238: Changing the Division Operator/ PEP 238: Changing the Division Operator/ PEP 238: Changing the Division Operator/ PEP 238: Changing the Division Operator/ // // // // // // PEP 274: Dict Comprehensions / PEP 274: Dict Comprehensions / PEP 274: Dict Comprehensions / PEP 274: Dict Comprehensions / PEP 274: Dict Comprehensions / PEP 274: Dict Comprehensions / {k: v for k, v in stuff} {k: v for k, v in stuff} {k: v for k, v in stuff} {k: v for k, v in stuff} {k: v for k, v in stuff} {k: v for k, v in stuff} Set literals and comprehensions Set literals and comprehensions Set literals and comprehensions Set literals and comprehensions Set literals and comprehensions Set literals and comprehensions                               13 / 38
  13. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 3.3 (released 2012) Python 3.3 (released 2012) Python 3.3 (released 2012) Python 3.3 (released 2012) Python 3.3 (released 2012) Python 3.3 (released 2012) PEP 397: Python Launcher for Windows / PEP 397: Python Launcher for Windows / PEP 397: Python Launcher for Windows / PEP 397: Python Launcher for Windows / PEP 397: Python Launcher for Windows / PEP 397: Python Launcher for Windows / py command py command py command py command py command py command PEP 405: Virtual Environments PEP 405: Virtual Environments PEP 405: Virtual Environments PEP 405: Virtual Environments PEP 405: Virtual Environments PEP 405: Virtual Environments PEP 420: Implicit Namespace Packages PEP 420: Implicit Namespace Packages PEP 420: Implicit Namespace Packages PEP 420: Implicit Namespace Packages PEP 420: Implicit Namespace Packages PEP 420: Implicit Namespace Packages PEP 380: Syntax for Delegating to a Subgenerator/ PEP 380: Syntax for Delegating to a Subgenerator/ PEP 380: Syntax for Delegating to a Subgenerator/ PEP 380: Syntax for Delegating to a Subgenerator/ PEP 380: Syntax for Delegating to a Subgenerator/ PEP 380: Syntax for Delegating to a Subgenerator/ yield from yield from yield from yield from yield from yield from PEP 414: Explicit Unicode literals / PEP 414: Explicit Unicode literals / PEP 414: Explicit Unicode literals / PEP 414: Explicit Unicode literals / PEP 414: Explicit Unicode literals / PEP 414: Explicit Unicode literals / u"abc" u"abc" u"abc" u"abc" u"abc" u"abc"                               14 / 38
  14. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 3.4 (released 2014) Python 3.4 (released 2014) Python 3.4 (released 2014) Python 3.4 (released 2014) Python 3.4 (released 2014) Python 3.4 (released 2014) PEP 453: Explicit Bootstrapping of PIP in Python Installations PEP 453: Explicit Bootstrapping of PIP in Python Installations PEP 453: Explicit Bootstrapping of PIP in Python Installations PEP 453: Explicit Bootstrapping of PIP in Python Installations PEP 453: Explicit Bootstrapping of PIP in Python Installations PEP 453: Explicit Bootstrapping of PIP in Python Installations PEP 435: Adding an Enum type to the Python standard library PEP 435: Adding an Enum type to the Python standard library PEP 435: Adding an Enum type to the Python standard library PEP 435: Adding an Enum type to the Python standard library PEP 435: Adding an Enum type to the Python standard library PEP 435: Adding an Enum type to the Python standard library PEP 428: The pathlib module – object-oriented lesystem paths PEP 428: The pathlib module – object-oriented lesystem paths PEP 428: The pathlib module – object-oriented lesystem paths PEP 428: The pathlib module – object-oriented lesystem paths PEP 428: The pathlib module – object-oriented lesystem paths PEP 428: The pathlib module – object-oriented lesystem paths PEP 450: Adding A Statistics Module To The Standard Library PEP 450: Adding A Statistics Module To The Standard Library PEP 450: Adding A Statistics Module To The Standard Library PEP 450: Adding A Statistics Module To The Standard Library PEP 450: Adding A Statistics Module To The Standard Library PEP 450: Adding A Statistics Module To The Standard Library                         15 / 38
  15. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 3.5 (released 2015) Python 3.5 (released 2015) Python 3.5 (released 2015) Python 3.5 (released 2015) Python 3.5 (released 2015) Python 3.5 (released 2015) PEP 492: coroutines with async and await syntax PEP 492: coroutines with async and await syntax PEP 492: coroutines with async and await syntax PEP 492: coroutines with async and await syntax PEP 492: coroutines with async and await syntax PEP 492: coroutines with async and await syntax PEP 465: a new matrix multiplication operator: PEP 465: a new matrix multiplication operator: PEP 465: a new matrix multiplication operator: PEP 465: a new matrix multiplication operator: PEP 465: a new matrix multiplication operator: PEP 465: a new matrix multiplication operator: a @ b a @ b a @ b a @ b a @ b a @ b PEP 484: Type Hints PEP 484: Type Hints PEP 484: Type Hints PEP 484: Type Hints PEP 484: Type Hints PEP 484: Type Hints PEP 441: Improving Python ZIP Application Support PEP 441: Improving Python ZIP Application Support PEP 441: Improving Python ZIP Application Support PEP 441: Improving Python ZIP Application Support PEP 441: Improving Python ZIP Application Support PEP 441: Improving Python ZIP Application Support PEP 471: os.scandir() function a better and faster directory iterator PEP 471: os.scandir() function a better and faster directory iterator PEP 471: os.scandir() function a better and faster directory iterator PEP 471: os.scandir() function a better and faster directory iterator PEP 471: os.scandir() function a better and faster directory iterator PEP 471: os.scandir() function a better and faster directory iterator                               16 / 38
  16. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 3.6 (released 2016) Python 3.6 (released 2016) Python 3.6 (released 2016) Python 3.6 (released 2016) Python 3.6 (released 2016) Python 3.6 (released 2016) PEP 498: formatted string literals: PEP 498: formatted string literals: PEP 498: formatted string literals: PEP 498: formatted string literals: PEP 498: formatted string literals: PEP 498: formatted string literals: f"{func()}" f"{func()}" f"{func()}" f"{func()}" f"{func()}" f"{func()}" PEP 515: underscores in numeric literals PEP 515: underscores in numeric literals PEP 515: underscores in numeric literals PEP 515: underscores in numeric literals PEP 515: underscores in numeric literals PEP 515: underscores in numeric literals PEP 526: syntax for variable annotations PEP 526: syntax for variable annotations PEP 526: syntax for variable annotations PEP 526: syntax for variable annotations PEP 526: syntax for variable annotations PEP 526: syntax for variable annotations PEP 525: asynchronous generators PEP 525: asynchronous generators PEP 525: asynchronous generators PEP 525: asynchronous generators PEP 525: asynchronous generators PEP 525: asynchronous generators PEP 530: asynchronous comprehensions PEP 530: asynchronous comprehensions PEP 530: asynchronous comprehensions PEP 530: asynchronous comprehensions PEP 530: asynchronous comprehensions PEP 530: asynchronous comprehensions PEP 506: Adding A Secrets Module To The Standard Library PEP 506: Adding A Secrets Module To The Standard Library PEP 506: Adding A Secrets Module To The Standard Library PEP 506: Adding A Secrets Module To The Standard Library PEP 506: Adding A Secrets Module To The Standard Library PEP 506: Adding A Secrets Module To The Standard Library                                     17 / 38
  17. Important changes in each version Important changes in each version

    Important changes in each version Important changes in each version Important changes in each version Important changes in each version Python 3.7 (scheduled for release 2018) Python 3.7 (scheduled for release 2018) Python 3.7 (scheduled for release 2018) Python 3.7 (scheduled for release 2018) Python 3.7 (scheduled for release 2018) Python 3.7 (scheduled for release 2018) PEP 553: Built-in breakpoint() PEP 553: Built-in breakpoint() PEP 553: Built-in breakpoint() PEP 553: Built-in breakpoint() PEP 553: Built-in breakpoint() PEP 553: Built-in breakpoint() PEP 557: Data Classes PEP 557: Data Classes PEP 557: Data Classes PEP 557: Data Classes PEP 557: Data Classes PEP 557: Data Classes Modify to impliment ssl packeage Modify to impliment ssl packeage Modify to impliment ssl packeage Modify to impliment ssl packeage Modify to impliment ssl packeage Modify to impliment ssl packeage                   18 / 38
  18. To compare the old style To compare the old style

    To compare the old style To compare the old style To compare the old style To compare the old style with the new style with the new style with the new style with the new style with the new style with the new style for the syntax and the structure for the syntax and the structure for the syntax and the structure for the syntax and the structure for the syntax and the structure for the syntax and the structure There isn’t enough time to cover everything in detail. There isn’t enough time to cover everything in detail. There isn’t enough time to cover everything in detail. There isn’t enough time to cover everything in detail. There isn’t enough time to cover everything in detail. There isn’t enough time to cover everything in detail. 20 / 38
  19. import () Multi-line Imports import () Multi-line Imports import ()

    Multi-line Imports import () Multi-line Imports import () Multi-line Imports import () Multi-line Imports All version All version All version All version All version All version from module_name import func1, func2, \ func3, func4, \ func5, func6 Python 2.4 + Python 2.4 + Python 2.4 + Python 2.4 + Python 2.4 + Python 2.4 + from module_name import (func1, func2, func3, func4, func5, func6) 21 / 38
  20. list.sort vs sorted(list) list.sort vs sorted(list) list.sort vs sorted(list) list.sort

    vs sorted(list) list.sort vs sorted(list) list.sort vs sorted(list) All version (Less memory, but has side effect) All version (Less memory, but has side effect) All version (Less memory, but has side effect) All version (Less memory, but has side effect) All version (Less memory, but has side effect) All version (Less memory, but has side effect) li = [1, 3, 10, 2, 5] li.sort() Python 2.4 + Python 2.4 + Python 2.4 + Python 2.4 + Python 2.4 + Python 2.4 + (No side effect) (No side effect) (No side effect) (No side effect) (No side effect) (No side effect) li = [1, 3, 10, 2, 5] new_li = sorted(li) 22 / 38
  21. Conditional Expressions Conditional Expressions Conditional Expressions Conditional Expressions Conditional Expressions

    Conditional Expressions All version All version All version All version All version All version if condition: x = true_value else: x = false_value Like this Like this Like this Like this Like this Like this x = condition and true_value or false_value Python 2.5+ Python 2.5+ Python 2.5+ Python 2.5+ Python 2.5+ Python 2.5+ x = true_value if condition else false_value 23 / 38
  22. with with with with with with All version All version

    All version All version All version All version f = open("filename.txt") data = f.read() f.close() Python2.6 + Python2.6 + Python2.6 + Python2.6 + Python2.6 + Python2.6 + with open("filename.txt") as f: data = f.read() 24 / 38
  23. %s vs str.format vs f-string %s vs str.format vs f-string

    %s vs str.format vs f-string %s vs str.format vs f-string %s vs str.format vs f-string %s vs str.format vs f-string All version All version All version All version All version All version from datetime import date s = "Today: %s" % date.today() Python 2.6 + Python 2.6 + Python 2.6 + Python 2.6 + Python 2.6 + Python 2.6 + from datetime import date s = "Today: {}".format(date.today()) Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + from datetime import date s = f"Today: {date.today()}" 25 / 38
  24. except Exception, e vs except Exception, e vs except Exception,

    e vs except Exception, e vs except Exception, e vs except Exception, e vs except Exception as e except Exception as e except Exception as e except Exception as e except Exception as e except Exception as e Python 2 Python 2 Python 2 Python 2 Python 2 Python 2 try: 1/0 except Exception, e: return e Python 2.6+ Python 2.6+ Python 2.6+ Python 2.6+ Python 2.6+ Python 2.6+ try: 1/0 except Exception as e: return e 26 / 38
  25. print statement vs print() function print statement vs print() function

    print statement vs print() function print statement vs print() function print statement vs print() function print statement vs print() function Python2 Python2 Python2 Python2 Python2 Python2 print "message" Python3 Python3 Python3 Python3 Python3 Python3 print("message") 27 / 38
  26. / vs // / vs // / vs // /

    vs // / vs // / vs // Python 2 Python 2 Python 2 Python 2 Python 2 Python 2 >>> 5 / 2 2 >>> 5 / 2.0 2.5 Python 3 Python 3 Python 3 Python 3 Python 3 Python 3 >>> 5 / 2 2.5 >>> 5 // 2 2 28 / 38
  27. dict Comprehensions dict Comprehensions dict Comprehensions dict Comprehensions dict Comprehensions

    dict Comprehensions Python 2 Python 2 Python 2 Python 2 Python 2 Python 2 dic = dict((str(i), i) for i in range(10)) Python 3 Python 3 Python 3 Python 3 Python 3 Python 3 dic = {str(i): i for i in range(10)} 29 / 38
  28. enum (Python 3.4 +) enum (Python 3.4 +) enum (Python

    3.4 +) enum (Python 3.4 +) enum (Python 3.4 +) enum (Python 3.4 +) Python 3.4 + Python 3.4 + Python 3.4 + Python 3.4 + Python 3.4 + Python 3.4 + import enum class Tast(enum.IntEnum): todo = 1 in_progress = 2 done = 3 @classmethod def get_task_types(cls): return tuple((x.value, x.name) for x in cls) 30 / 38
  29. enum (Python 3.3) enum (Python 3.3) enum (Python 3.3) enum

    (Python 3.3) enum (Python 3.3) enum (Python 3.3) Python 3.3 Python 3.3 Python 3.3 Python 3.3 Python 3.3 Python 3.3 class Task: todo = 1 in_progress = 2 done = 3 task_types = ( (todo, "todo"), (in_progress, "in_progress"), (done, "done")) 31 / 38
  30. @ operator @ operator @ operator @ operator @ operator

    @ operator >>> import numpy as np >>> a = np.array([[1, 2]]) >>> b = np.array([[3], [4]]) Python3.4 Python3.4 Python3.4 Python3.4 Python3.4 Python3.4 >>> np.dot(a, b) array([[11]]) Python3.5+ Python3.5+ Python3.5+ Python3.5+ Python3.5+ Python3.5+ >>> a @ b array([[11]]) 32 / 38
  31. pathlib pathlib pathlib pathlib pathlib pathlib Python 3.5 Python 3.5

    Python 3.5 Python 3.5 Python 3.5 Python 3.5 import os current = os.getcwd() filepath = os.path.join(current, "dir", "filename.txt") with open(filepath) as f: data = f.read() Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + from pathlib import Path p = Path(".") / "dir" / "filename.txt" with p.open() as f: data = f.read() 33 / 38
  32. os.listdir() vs pathlib os.listdir() vs pathlib os.listdir() vs pathlib os.listdir()

    vs pathlib os.listdir() vs pathlib os.listdir() vs pathlib Python 3.5 Python 3.5 Python 3.5 Python 3.5 Python 3.5 Python 3.5 import os for name in os.listdir(PATH): if not name.startswith('.') and os.path.isfile(os.path.join(PATH, nam e)): print(name) Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + from pathlib import Path for entry in Path(PATH).iterdir(): if not entry.name.startswith('.') and entry.is_file(): print(entry.name) 34 / 38
  33. secrets module secrets module secrets module secrets module secrets module

    secrets module Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + Python 3.6 + from secrets import choice import string alphabet = string.ascii_letters + string.digits password = ''.join(choice(alphabet) for i in range(8)) In particularly, secrets should be used in preference to the default In particularly, secrets should be used in preference to the default pseudo-random number generator in the random module, which is designed for pseudo-random number generator in the random module, which is designed for modelling and simulation, not security or cryptography. modelling and simulation, not security or cryptography. https://docs.python.org/3/library/secrets.html https://docs.python.org/3/library/secrets.html https://docs.python.org/3/library/secrets.html https://docs.python.org/3/library/secrets.html https://docs.python.org/3/library/secrets.html https://docs.python.org/3/library/secrets.html 35 / 38
  34. Data Classes Data Classes Data Classes Data Classes Data Classes

    Data Classes Python 3.7 + Python 3.7 + Python 3.7 + Python 3.7 + Python 3.7 + Python 3.7 + @dataclass class InventoryItem: name: str unit_price: float quantity_on_hand: int = 0 def total_cost(self) -> float: return self.unit_price * self.quantity_on_hand 36 / 38
  35. Data Classes Data Classes Data Classes Data Classes Data Classes

    Data Classes Python 3.6 Python 3.6 Python 3.6 Python 3.6 Python 3.6 Python 3.6 class InventoryItem: def __init__(self, name: str, unit_price: float, quantity_on_hand: int = 0) -> None: self.name = name self.unit_price = unit_price self.quantity_on_hand = quantity_on_hand .... (some special compare method) def total_cost(self) -> float: return self.unit_price * self.quantity_on_hand 37 / 38