Python Comparison Operators

In Python, comparison operators are used to compare the values on either side of the operators and then decide the relationship between them (sometimes they’re also referred to as relational operators). What follows is a complete list of the comparison operators in Python. Some of them might be pretty self-explanatory, while others you may have […]

Read More

Python’s null equivalent: None

What is the null or None Keyword The null keyword is commonly used in many programming languages, such as Java, C++, C# and Javascript. It is a value that is assigned to a variable. Perhaps you have seen something like this: null in Javascript

null in PHP

null in Java

The concept […]

Read More

Memory-Mapped (mmap) File Support in Python

What is a Memory-Mapped File in Python From Python’s official documentation, be sure to checkout Python’s mmap module: A memory-mapped file object behaves like both strings and like file objects. Unlike normal string objects, however, these are mutable. Basically, a memory-mapped (using Python’s mmap module) file object maps a normal file object into memory. This […]

Read More

Lambda Function Syntax (Inline Functions) in Python

Python’s syntax is relatively convenient and easy to work with, but aside from the basic structure of the language Python is also sprinkled with small syntax structures that make certain tasks especially convenient. The lambda keyword/function construct is one of these, where the creators call it “syntactical candy”. Here we’ll examine how to use them. To understand the lambda keyword/function and their […]

Read More

Catching Python Exceptions – The try/except/else keywords

Often times when coding a python masterpiece, there are certain things that could go wrong when executing your masterfully designed code. Things such as files or directories that are missing, empty strings, variables that are supposed to be strings but are actually arrays at run-time. These things are called exceptions in Python. This is what […]

Read More

Cutting and slicing strings in Python

Python strings as sequences of characters Python strings are sequences of individual characters, and share their basic methods of access with those other Python sequences – lists and tuples. The simplest way of extracting single characters from strings (and individual members from any sequence) is to unpack them into corresponding variables.

Unfortunately, it’s not […]

Read More

Python Decorators Overview

Decorators in Python seem complicated, but they’re very simple. You’ve probably seen them; they’re the odd bits before a function definition that begin with ‘@’, e.g.:

Note the function called decorator; it takes a function as an argument and defines and returns a new function that uses the one it was passed. That pattern […]

Read More

List Comprehension in Python

Sometimes we need to generate lists which follow some natural logic, such as iterating over a sequence and applying some conditions in them. We can use Python’s “list comprehension” technique to write compact codes to generate lists. We can loop through a sequence, and apply logical expression. First, let’s look at a special function range […]

Read More

Using the Python Tempfile Module

While programming in Python, there will likely be times where you have some data that needs to be utilized or manipulated in the form of a file but hasn’t yet been written to one. Naturally, the first solution that comes to mind is to open a new or existing file, write the data and finally […]

Read More

Reading and Writing to Files in Python

Manipulating files is an essential aspect of scripting in Python, and luckily for us, the process isn’t complicated. The built-in open function is the preferred method for reading files of any type, and probably all you’ll ever need to use. Let’s first demonstrate how to use this method on a simple text file. For clarity, […]

Read More