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?

Debugging Python Code Is Like Detective Work — Let’s Investigate

Sherlock Holmes in Debugging Python code

Debugging Python code is not a mysterious art form. It's like a detective solving a mystery. This analogy comes from one of my favourite programming aphorisms: "Debugging is like being the detective in a crime movie where you are also the murderer" (Felipe Fortes). So what can real detectives tell us about debugging Python code?… Continue reading Debugging Python Code Is Like Detective Work — Let’s Investigate

Simulating a 3D Solar System In Python Using Matplotlib (Orbiting Planets Series #2)

One of the uses of programming is to help us understand the real world through simulation. This technique is used in science, finance, and many other quantitative fields. As long as the "rules" which govern the real-world properties are known, you can write a computer program that explores the outcomes you get from following those… Continue reading Simulating a 3D Solar System In Python Using Matplotlib (Orbiting Planets Series #2)

Practise Using Lists, Tuples, Dictionaries, and Sets in Python With the Chaotic Balls Animation

Using lists tuples dictionaries and sets in Python

One of the early topics covered when learning to code deals with the built-in data structures in Python. Lists are usually learned early on, followed by dictionaries and tuples. Sets are not normally one of the earliest topics covered. However, that's not because they're complex but because they're used less often in Python. Understanding the… Continue reading Practise Using Lists, Tuples, Dictionaries, and Sets in Python With the Chaotic Balls Animation

Python City: Understanding how a Python Program Works (The White Room Series #3)

You've written a Python script or a project containing several modules. You press Run, figuratively or literally. What happens behind the scenes in the microseconds or seconds or minutes it takes for your program to run? You can dive into the details about the internal functioning of Python to learn how a Python program works.… Continue reading Python City: Understanding how a Python Program Works (The White Room Series #3)