Python Try Except: An Illustrated Guide

What is Try/Except in Python? Python’s try and except keywords are used to ‘catch’ an exception and handle it, preventing it from terminating your program as it normally would. This could be useful in situations where you know there’s potential for an exception to occur, and you want your program to be able to continue … Read more

How to Print Colored Text in Python?

Summary: To print colored text in Python, you can use: The simple_color package, The ‘\033[1m’ ANSI escape-sequence, The termcolor module, The coloroma package, The colored library, 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[38;5;4m”). We’ll … Read more

How to Extract Numbers from a String

Problem Formulation and Solution Overview In this article, you’ll learn how to extract numbers from a string in Python. To make it more fun, we have the following running scenario: This article references an Albanian proverb written by Driton Selmani in 2012. We will leave the interpretation up to you. 💬 Question: How would we … Read more

How to Add a Column to a CSV

Problem Formulation and Solution Overview In this article, you’ll learn how to add a new column to a CSV file in Python. To make it more fun, we have the following running scenario: The owner of the Finxter Academy has asked you to add a new column to their existing CSV file called Total_Chrgs. 💬 … Read more

How to Print Italic Text in Python?

You can change your text to bold, italic, and underlined in Python. Not only can you play around with the style of your code but also change its color with the help of specific packages and modules in Python. Interesting! Isn’t it? There are different ways of doing this. By the end of this tutorial, … Read more

Maximum Recursion Depth in Python  

What is Recursion? Recursion in programming is a problem-solving concept. In recursion, a function finds the solution by calling itself once or many times. This function call can be explicit or implicit. 💡Info: Recursion, according to (Tang 2013), is when a function or algorithm calls itself one or more times. These calls occur until the … Read more

How to Add Time Onto a Datetime Object in Python

[toc] Problem: Given a datetime.datetime object in Python, is there a way to add time to the given datetime object? Related Question on StackOverflow: Discussion: Adding time to a datetime object in Python should lead to a new datetime object with the updated time information. For example, if you add 5 hours to a datetime … Read more

How to Print Bold Text in Python?

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”). We’ll discuss this most Pythonic solution in Method 2 in this article. You can change your text to bold, italic, and underlined in Python. Not only … Read more