Expert Python Programming(Third Edition)
上QQ阅读APP看书,第一时间看更新

Modern Syntax Elements - Below the Class Level

Python has evolved a lot in the last few years. From the earliest version to the current one (3.7 at this time), a lot of enhancements have been made to make the language clearer, cleaner, and easier to write. Python basics have not changed drastically, but the tools it provides are now a lot more ergonomic.

As Python evolves, your software should too. Taking great care over how your program is written weighs heavily on how it will evolve. Many programs end up being ditched and rewritten from scratch because of their obtuse syntax, unclear APIs, or unconventional standards. Using new features of a programming language that make your code more expressive and readable increases the maintainability of your software and so prolongs its lifetime.

This chapter presents the most important elements of modern Python syntax, and tips on their usage. We will also discuss some implementation details of the built-in Python types that have various implications on your code performance, but we won't be digging too much into optimization techniques. The code performance tips for speed improvement or memory usage will be covered later in Chapter 13, Optimization – Principles and Profiling Techniques, and Chapter 14, Optimization – Some Powerful Techniques.

In this chapter, we will cover the following topics:

  • Python's built-in types
  • Supplemental data types and containers
  • Advanced syntax
  • Functional-style features of Python
  • Function and variable annotations
  • Other syntax elements you may not know yet