Method and Function overriding is an extremely useful technique. It allows you to define the same method multiple times in your code — but with each method taking parameters of a different type.
Methods are defined on classes. Overloading is what happens when a child class redefines the method available in a parent class. Therefore we call this method overloading. I won’t be discussing method overloading in this article.
Functions are not defined on class objects (normally). When we define multiple versions of a function, it is called function overriding. This article is about function overriding in Python.
Let’s explore many different methods and techniques for calculating the Fibonacci Series using Python.
The Fibonacci Series is beautiful, fascinating, mysterious! The series is defined as follows: every number is the sum of the two preceding ones. Simple:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
The simplest way to calculate a Fibonacci number (n) is simply to start at the beginning and work forwards, iteratively. This solution calculates all previous values, giving it an exponential running time — larger numbers take increasingly longer to calculate.
The recursive approach to finding Fibonacci numbers…
Beginner guide to understanding Python’s slice object.
If you’re unsure about how Python indexes and slices strings, this article is for you! First, let’s explore indexes. (Indices for the grammatically correct!).
This is a companion article to my beginner series:
The first element in a sequence has the index 0. Not 1. This is often a source of confusion!
Some reusable python recipes for manipulating bits to perform fast arithmetic.
<< operator to shift bits one place to the left, thereby doubling an integer.
>> operator to shift bits one place to the right, thereby halving an integer.
This is more complicated. The pseudocode algorithm is:
while a ≠ 0
c ← b and a
b ← b xor a
left shift c by 1
a ← c
Which, in principle, uses a loop which ends when the first integer reaches 0 — all of its bits have been added to…
This article is for Python programmers who have gone beyond the basics of using
lists, but would like to see some interesting concepts. It isn’t very advanced and should be easy for you to understand.
Sets contain unique elements but are unordered. On the other hand, lists can contain duplicate elements but retain their insertion order.
This example shows one way to get the benefits of both sets and lists — an ordered sequence of unique elements.
We are subclassing the Python built-in
collections.UserList object. We could subclass
list, or use
collections.abc to create a new abstract base class of…
The following code snippets are available on Github as Gists, and were tested with Python 3.7. This is a companion article to:
This is a recursive solution to printing all k:v pairs in a dictionary.
It handles the presence of lists, sets and tuples in a value.
This is the output produced:
String manipulation is something we Pythonistas do a lot. Here are 20 top tips & tricks you might find useful!
Use the in-built comparator
in which returns
Use a slice with a decreasing step to return the reversed string.
Compare equality using
== to see if two objects have an equal value. …
It was mostly painful. Herein follows a compression algorithm for experience.
1. The AWS training ecosystem is a hot mess of different websites and flaky SSO protocols. Be prepared to login several times. Your amazon.com account is used, not your AWS account, for … reasons. Your entry point is https://aws.training/. ¯\_(ツ)_/¯
2. You can schedule “At Home Alone” AWS certifications via PearsonVue. (Entry point listed above). This requires waving away any privacy you had left and installing their super-pervasive “Online Proctoring” software. Nothing to see here.
3. If you take the $90 cloud practitioner exam, and then pass said exam…
I use these utilities every day to make my Python code presentable. They’re free and easy to use.
Writing beautiful Python is harder than it seems. As part of my release workflow, I use the following tools to make my code presentable and to remove avoidable mistakes.
You can get black from pypi using pip3:
pip3 install --upgrade --user black
Black has rich options, use
black -h to print the help text.
black -t py38 --check…
Let’s explore the powerful object-oriented programming concepts available to us in Python!
This article is part of the course “Object-Oriented Python — for Beginners”. If you’re looking for a more beginner-oriented “Introduction to Python” course, I created one just for you! This course takes things a step further and delves deep into object-oriented Python. Earlier we saw how the
tuple data type is used to create a record. The
class can do the same, but it also allows us to bundle functions alongside the data.
Python is an object-based programming language. Every data type, and every variable, is an object…
I am a software engineering manager with over 25 years of experience. I am working to improve people’s health. Based in Basel, Switzerland.