Cool stuff in Python 3 you might not be using

Explore new language features, type hinting, and noteworthy features in Python 3, and learn how to apply them to improve code legibility, reliability, and performance in real-world applications.

Key takeaways

New Language Features

  • Parenthesized contexts: allow tuple-like functionality
  • F-strings: string formatting with variables
  • KWOnlyArgkwargs syntax: keyword-only arguments
  • AsyncIO: Python’s built-in async and await support

Type Hinting

  • Annotate types: specify function return types and parameter types
  • Type checking: use mypy for static type checking

Other Noteworthy Features

  • Walrus operator: allows assignment within an expression
  • Union operator: combine two lists or dictionaries
  • TypeDict: create a typed dictionary
  • Advanced destructuring: break down values into multiple variables

Insights

  • Python 3 has been around since 2008, with significant improvements made since
  • Python 3.9 introduced a new feature allowing you to directly integrate the random module with the statistics module
  • Practices like keyword-only arguments, type hinting, and async/await can improve code legibility and reliability

Real-World Applications

  • The speaker’s company converted from Python 2 to Python 3; many existing tests needed to be updated for Unicode support
  • PyQt is still cross-platform and is not abandoned
  • MassChallenge is a startup accelerator that uses Python for their platform; they have a pool of 1000 mentors for their entrepreneurs