From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Write Pythonic code

Write Pythonic code - Python Tutorial

From the course: Python: Programming Efficiently

Start my 1-month free trial

Write Pythonic code

- [Instructor] Idiomatic Python code, often called Pythonic, is code that embodies the design principles of the language. It's code that is true to Python's spirit. Furthermore, the Pythonic solution to a programming problem is usually the most efficient and most readable way to solve it. With this in mind, let us see how we can refactor a few snippets of code to make them more Pythonic. We use iterators and comprehensions and a few more idioms, including F strings, generic function arguments, and the built-ins all and any. I start by importing all the packages that we need. And here's some data that we need from the previous videos. The principles of Pythonic programming are described by an Easter egg within the language itself. It's the Zen of Python, which we get my running import this. It's worth thinking about all of these but my favorites are beautiful is better than ugly, simple is better than…

Contents