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]

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

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

Simulating a tennis match using object-oriented programming in Python

With Wimbledon underway, I thought of paying homage to the classic tennis tournament with a program simulating a tennis match in Python. I'll use this program to explore several key concepts in Object-Oriented Programming. You'll write a program which will allow you to do two things: Part 1: You can keep the score of a… Continue reading Simulating a Tennis Match Using Object-Oriented Programming in Python—Wimbledon Special Part 1

numpy.meshgrid(): How Does It Work? When Do You Need It? Are There Better Alternatives?

A mesh grid representing numpy.meshgrid

You have come across numpy.meshgrid() already. You may even have used it. But do you know what it does and how it does it? If your answer is "I'm not sure", then you're not alone. Some people find this function hard to understand. Others understand what it does but not why it's needed. And some… Continue reading numpy.meshgrid(): How Does It Work? When Do You Need It? Are There Better Alternatives?