What’s a Python Sequence? [Python Data Structure Series #2]

Image of wooded boxes — used in article on Python sequences

Note: This article has now moved here: Sequences in Python (Data Structure Categories #2) – Sequences are different from iterables • Part 2 of the Data Structure Categories Series Here's an introduction to the article: You started your journey through Python's main data structure categories in the first article in this series, which dealt with… Continue reading What’s a Python Sequence? [Python Data Structure Series #2]

What’s a Python Iterable? [Python Data Structure Series #1]

Old boxes - image used in Python data structure series

Note: This article has now moved here: Iterable: Python's Stepping Stones – What makes an iterable iterable? Part 1 of the Data Structure Categories Series Here's an introduction to the article: You're familiar with data structures such as lists, dictionaries, tuples, sets, and more. You may even know about the similarities and differences between their… Continue reading What’s a Python Iterable? [Python Data Structure Series #1]

Anatomy of a 2D Game using Python’s turtle and Object-Oriented Programming

2D Python game

When I was young, we played arcade games in their original form on tall rectangular coin-operated machines with buttons and joysticks. These games had a resurgence as smartphone apps in recent years, useful to keep one occupied during a long commute. In this article, I'll resurrect one as a 2D Python game and use it… Continue reading Anatomy of a 2D Game using Python’s turtle and Object-Oriented Programming

Understanding The Difference Between `is` and `==` in Python: The £5 Note and a Trip to a Coffee Shop

Coffee cup and a £5 note to show difference between 'is' and '==' in Python

The keyword is and the operator == are not the same. Yet, many programmers often use one when they should use the other. Let's look at the difference between is and == in Python with the help of a £5 note and a trip to my local coffee shop. In this article, you'll: Find out… Continue reading Understanding The Difference Between `is` and `==` in Python: The £5 Note and a Trip to a Coffee Shop

Some Best Practices When Writing Python Functions [Intermediate Python Functions Series #7]

You've covered a lot of material in this Intermediate Python Functions Series. In this final article, you'll read about some best practices in Python functions. This topic is different from the previous ones discussed in this series. You won't get a SyntaxError, TypeError or any other error if you don't follow best practices. Your code… Continue reading Some Best Practices When Writing Python Functions [Intermediate Python Functions Series #7]

Using Python’s NumPy To Improve Your Board Game Strategy: Your Odds When Attacking in ‘Risk’

Image of board game - NumPy and Board Games in Python

I first played the board game Risk during my doctoral studies. We occasionally stayed up all night playing this game. I hadn't played it for many years, but I bought it "for the kids" this Christmas, so I got to play it again. And soon, I found myself wondering what the odds are for the… Continue reading Using Python’s NumPy To Improve Your Board Game Strategy: Your Odds When Attacking in ‘Risk’

Using Type Hints When Defining A Python Function [Intermediate Python Functions Series #6]

You've already covered a lot of ground in this Intermediate Python Functions series. In this article, you'll read about a relatively new addition in Python called type hinting or type annotation. Unlike all the other topics you learnt about in the previous articles, this one will not change the behaviour of the function you define.… Continue reading Using Type Hints When Defining A Python Function [Intermediate Python Functions Series #6]

Using Positional-Only And Keyword-Only Arguments in Python [Intermediate Python Functions Series #5]

Cogwheels (steampunk style) to represent Python functions

In previous articles in this series, you read about positional and keyword arguments, making arguments optional by adding a default value, and including any number of positional and keyword arguments using *args and **kwargs. In this article, it's the turn of another flavour of argument. You'll look at parameters that can only accept positional arguments… Continue reading Using Positional-Only And Keyword-Only Arguments in Python [Intermediate Python Functions Series #5]

Argh! What are args and kwargs in Python? [Intermediate Python Functions Series #4]

cogs and wheels used to represent functions in the args and kwargs in Python article

In the first three articles in this Series, you familiarised yourself with the key terms when dealing with functions. You also explored positional and keyword arguments and optional arguments with default values. In this article, you'll look at different types of optional arguments. Rather unfortunately, these are often referred to by the obscure names args… Continue reading Argh! What are args and kwargs in Python? [Intermediate Python Functions Series #4]

Write A Football Offside Rule Quiz in Python While Practising Object-Oriented Programming

Offside Rule Python Quiz: silhouette of player kicking the moon

Do you know the offside rule in football*? Or do you want to test whether someone else knows it well enough? Either way, it's time to write an offside rule quiz in Python using object-oriented programming. (*Some of you may call it "soccer") Here's what the quiz will look like. The program presents you with… Continue reading Write A Football Offside Rule Quiz in Python While Practising Object-Oriented Programming