Topic Archive

Concepts

  • This is the third part of a series of articles dealing with the type annotation system in Python, type hints for short. The second part discussed a set of beginner examples and highlighted the benefits of using type hints. This article series is aimed at newcomers to type hints and wants to help you get started. In this third part, I will continue discussing slightly more advanced examples to further deepen your knowledge about type hints. Each example will cover a certain topic and look at type hints from a slightly different perspective. Most examples will end with a tip…


  • This is the second part of a series of articles dealing with the type annotation system in Python, type hints for short. The first part gave an introduction to type hints. This article is aimed at newcomers to type hints and wants to help you get started. In this second part, I will go over a handful of carefully chosen examples of how to use basic type hints to solve a particular problem and improve the overall code quality and readability. Each example will cover a certain topic and look at type hints from a slightly different perspective. Most examples…


  • This is the first part of a series of articles dealing with the type annotation system in Python, type hints for short. With this opinionated article, I advocate the use of type hints. I want to explain why you should care and why your code will be better, more bug-free, more accessible, and easier to maintain. At the end, I will give you some recommendations on how to get started. Type hints is a really huge topic and a quick look at the official documentation [4] is all it takes to feel a little lost. To be honest, I am…


  • 5 Helpful Python Decorator Use Cases

    ·

    ·

    2 min read

    Some time ago I asked on Twitter: I was curious what you use #Python decorators for?  And I got quite an amazing / insightful response: The obvious next step for me was to look at some examples / use cases. So below are 5 useful applications of decorators. Study them, then apply similar things to your own work. 1. De-duplicate code The first one was easiest, because @prashanttgs posted a great example: It’s easier for me to do: … for multiple functions than doing this: To me this shows the benefit of abstracting away repeated logic to make your functions (classes) leaner. …


  • Naughts and Crosses Gets a Little Help

    ·

    ·

    35 min read

    Naughts and Crosses (Tic-Tac-Toe to some audiences) is a popular skill game often played by children. It can also be usefully employed to distract dial up computers, at NORAD for example, rather than allowing the ‘playing’ of Global Thermonuclear War. Would you like to play a game?


  • Abstract Syntax Trees in Python

    ·

    ·

    16 min read

    In this article Alessandro provides an overview of Abstract Syntax Trees (ASTs), introduces a few use-cases, and showcases the ast module in the Python Standard Library. The content is structured in a top-down fashion, starting from general notion about an AST, and digging deeper up to the point of artificially manipulating an AST to “randomize” the content of some instructions.


  • Knowing the difference between mutable and immutable types in Python is important. In this article I will give you some practical examples of both and show you some of the advantages of using immutable types. We even look at JS / React / functional programming a bit towards the end.


  • When people come to Python one of the things they struggle with is OOP (Object Oriented Programming). Not so much the syntax of classes, but more when and when not to use them. If that’s you, read on. In this article I will give you some insights that will get you clarity on this.