IT developer, trainer, and author. Coauthor of the Debian Package Management Book (http://www.dpmb.org/).
Loops in Python
A programming language typically consists of several types of basic elements, such as assignments, conditionals, and loops. The idea behind a loop is to repeat a segment of code that is in the body of the loop. Different kinds of loops are common. For example, loops will run: while a...
Comparing Strings using Python
In Python, strings are sequences of characters, which are effectively stored in memory as an object. Each object can be identified using the id() method, as you can see below. Python tries to re-use objects in memory that have the same value, which also makes comparing objects very fast in...
Command Line Arguments in Python
With Python being a very popular programming language, as well as having support for most operating systems and many libraries that make command-line argument processing easy - it's become widely used to create command line tools for many purposes. These tools can range from simple CLI apps to those that...
Reading Files with Python
To work with stored data, file handling becomes the core knowledge of every professional Python programmer. Right from its earliest release, both reading and writing data to files are built-in Python features. In comparison to other programming languages like C or Java, it is pretty simple and only requires a...
Reading and Writing Lists to a File in Python
Python programmers intensively use arrays, lists, and dictionaries as serialized data structures. Storing these data structures persistently requires either a file or a database to properly work. In this article, we'll take a look at how to write a list to file, and how to read that list back into...
Writing Files using Python
As pointed out in a previous article that deals with reading data from files, file handling is essential knowledge of every professional and hobbyist Python programmer. This feature is a core part of the Python language, and no extra module needs to be loaded to do it properly. In this...
Python String Interpolation with the Percent (%) Operator
There are a number of different ways to format strings in Python, one of which is done using the % operator, which is known as the string formatting (or interpolation) operator. In this article we'll show you how to use this operator to construct strings with a template string and variables...
As already pointed out in a previous article titled Commenting Python Code you have learned that documentation is an essential, and a continuous step in the process of software development. The article mentioned above briefly introduced the concept of docstrings which is a way to create documentation for your Python...
Rounding Numbers in Python
Using a computer in order to do rather complex Math is one of the reasons this machine was originally developed. As long as integer numbers and additions, subtractions, and multiplications are exclusively involved in the calculations, everything is fine. As soon as floating point numbers or fractions, as well as...