How to Print Bold Text in Python?

Summary: To print bold text in Python, you can use: The simple_color package, The ‘\033[1m’ ANSI escape-sequence, The termcolor module, The coloroma package, The prompt_toolkit package. A simple, no-library way to print bolded text in Python is to enclose a given string s in the special escape sequence like so: print(“\033[1m” + s + “\033[0m”). … Read more

How to Count Vowels in a String

Problem Formulation and Solution Overview In this article, you’ll learn how to count the number of vowels in a string. To make it more fun, we have the following running scenario: In Canada, we have a province called Saskatchewan. This province has a large amount of flat land. In this article, we reference their local … Read more

How to Suppress Scientific Notation in Python

Summary: Use the string literal syntax f”{number:.nf}” to suppress the scientific notation of a number to its floating-point representation. Problem Formulation: How will you suppress a number represented in scientific notation by default to a floating-point value? Note: Generally, Python represents huge floating-point numbers or very small floating-point numbers in their scientific form. Scientific notation … Read more

Python Base64 – String Encoding and Decoding [+Video]

A Short Guide to Base64’s History and Purpose Base64 is a system of binary-to-text transcoding schemas, which enable the bidirectional transformation of various binary and non-binary content to plain text and back. Compared to binary content, storage and transfer of textual content over the network is significantly simplified and opens many possibilities for flexible data … Read more

How to Write Huge Amounts of Generated Data to a File in Python?

Problem formulation Sometimes we need to generate massive amounts of data. For example, to perform bootstrapping or jackknifing of our actual data. To get lots of parameterized dummy data, learn how to use new libraries or adjust the model’s hyperparameters. Or benchmark different solutions or debug and optimize our code. Generating this data is expensive, … Read more

How to Insert a String into Another String at a Given Index in Python? 

Let’s start this article with a quick question to understand your understanding of strings. 💬 Question: Can the string objects be modified in Python? What do you think? Well, the fact is String objects are immutable. They cannot be modified. Consider the below example :  Output: Now you might say, replacement operations and insertion operations … Read more

How to Remove Newlines from a List

Problem Formulation and Solution Overview In this article, you’ll learn how to remove the newline character from list elements in Python. To make it more fun, we have the following running scenario: Watts Security has contacted you for assistance. They have been given a flat file containing user account breaches. Upon review, they notice each … Read more

Replace Last Substring Occurrence in Python String

Problem Formulation Given a string, a substring, and a replacement string in Python. String s Substring sub Replacement string repl How to find and replace the last occurrence of sub with the replacement repl in the Python string s? Let’s have a look at a couple of examples to thoroughly understand the problem: Example 1: … Read more