Blog

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

Optional Arguments With Default Values in Python Functions [Intermediate Python Functions Series #3]

Steampunk hat with goggles

We continue our journey through Python functions by looking at optional arguments and default values. In this article, you'll see how you can define a function with an optional argument. A default value is used if the argument is not included in the function call. Overview Of The Intermediate Python Functions Series Here's an overview… Continue reading Optional Arguments With Default Values in Python Functions [Intermediate Python Functions Series #3]

Using Positional Arguments and Named or Keyword Arguments in Python Functions [Intermediate Python Functions Series #2]

Image of steampunk gears used to represent Python functions

In the first article in this Intermediate Python Functions Series, you made sure you got your terminology right. So you know what an argument is. But what are positional arguments and keyword arguments in Python? In this article, you'll see how you can choose to use either of the two in many situations. Later in… Continue reading Using Positional Arguments and Named or Keyword Arguments in Python Functions [Intermediate Python Functions Series #2]

Moving On From The Basics of Python Functions [#1 in Intermediate Python Functions Series]

Steampunk-themed cogs to represent Python functions

Those learning to code learn about functions very early on in their journey. Not only do beginners use Python functions right from their first lesson, but they also learn to define their own Python functions early on. It may be tempting–and in my experience, it's a common pitfall early on–for a relative beginner to think… Continue reading Moving On From The Basics of Python Functions [#1 in Intermediate Python Functions Series]

Mini-Post: Exploring Python Functions Through Experimentation

abstract background with swirls multicolor splashes of paints

Read the docs. Look at the source code. Yes, these are great tips to figure out what's happening underneath the hood. But sometimes you want to do a bit of experimentation and exploration of your own first. It's more fun this way. And sometimes more instructive, too. Here's something I came across today which I… Continue reading Mini-Post: Exploring Python Functions Through Experimentation

Functions in Python are Like a Coffee Machine

Functions in Python are like Coffee Machines - a coffee cup on a desk with computers

Functions in Python are one of those topics for beginners! Most understand what functions are at a basic level. However, there's much more detail and nuance to defining and calling functions in Python. As with most things in coding and Python, there's nothing better than a good analogy to picture what's happening behind the scenes.… Continue reading Functions in Python are Like a Coffee Machine

Shallow and Deep Copy in Python and How to Use __copy__()

Stormtroopers to show shallow and deep copy in Python

You need to make a copy of an object in a Python program. How difficult can it be? Not very. But you also need to know the difference between shallow and deep copy in Python and decide which one you need. In this article, you'll read about the difference between shallow and deep copy when… Continue reading Shallow and Deep Copy in Python and How to Use __copy__()

Part 2: Simulating a Tennis Match Using Object-Oriented Programming in Python—Wimbledon Special

How does the likelihood of winning a tennis match change as the likelihood of winning a single point changes? How about the probability of a best-of-five match ending in three sets? Let's have some fun exploring some of these questions using a Python tennis match simulation program. I won't try to factor in all the… Continue reading Part 2: Simulating a Tennis Match Using Object-Oriented Programming in Python—Wimbledon Special