Posts From Python Programming Examples

Merge Sort

Understanding Merge Sort in Python

In this article, we will be having a look at an efficient sorting algorithm – Merge Sort in Python. The merge sort algorithm is used to sort existing data in an ascending or descending order. Let’s look into how we can make use of the algorithm and implement it in Python. Working of Merge Sort […]

Python Random String Generation

How to Generate Random Strings in Python

In this article, we’ll take a look at how we can generate random strings in Python. As the name suggests, we need to generate a random sequence of characters, it is suitable for the random module. There are various approaches here, so we’ll start from the most intuitive one; using randomized integers. Build a string […]

Xml Parsing Python

Python XML Parser

Ever stuck with an annoying XML file that you need to parse to get important values? Let’s learn how to create a Python XML parser. We’ll look at how we can parse XML files like these using Python to get the relevant attributes and values. Let’s get started! Method 1: Using ElementTree (Recommended) We can […]

Python Increment Operation

Python Increment Operation

How do you perform a Python increment operation? If you’re coming from a language like C++ or Java, you may want to try extending a similar increment functionality to Python also. But, as we will see in this article, this is not quite the same. Let’s look at how we can try to use similar […]

Python Factorial

Python Factorial Examples

In this article, we’ll look at how we can calculate the Python factorial using different approaches. The Python Factorial function The Python factorial function factorial(n) is defined for a whole number n. This computes the product of all terms from n to 1. factorial(0) is taken to be 1. So, the function is: Therefore, factorial(4) […]

Python Print Without Newline

There are different ways through which we can print to the console without a newline. Let’s quickly go through some of these methods. 1. Using print() We can use the print() function to achieve this, by setting the end (ending character) keyword argument appropriately. By default, this is a newline character (\n). So, we must […]