Practical solutions

Python How-To's How-To Guides

Solve the problem. Keep building. The collection of Python-related howtos

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Mock Raise Exception in PythonThis tutorial demonstrates how to raise exceptions when we run the unit test with the help of the mock module. How to Convert Dataclass to JSON in PythonThis article navigates the process of converting Python dataclasses to JSON, best practices, and common issues. How to Retry a Loop in PythonThis tutorial shows and explains how to retry a loop action in a situation where the action fails initially in Python. Python VerboseThis article delves into the details of the verbose mode in Python, exploring its purpose, syntax, and practical applications in various programming scenarios. Derivative of ReLU Function in PythonThe ReLU function is most frequently used in machine learning in terms of deep learning. This article discusses how to implement ReLU derivation in Python along with implementing the ReLU function. How to Detect Keypress in PythonThis tutorial provides a demonstration of how to detect keypress on a keyboard in Python. How to Convert a String to Variable Name in Python In this article we will discuss various ways to convert a string value to a variable name in Python. How to Compare Two Dictionaries in PythonThis article explains the method of comparing two dictionaries Python. How to Calculate the Cumulative Distribution Function in PythonThis article explains the method of calculation of the Cumulative Distribution Function in Python. It can be calculated using numpy's arange() or linspace() functions How to Delete Files and Directories Using PythonWe can delete files and directories in Python using functions from inbuilt packages like os, pathlib and shutil. How to Call a Class in PythonThis tutorial demonstrates how to call an instance of a class in Python. How to Copy a File in PythonThis article introduces how to copy files in Python by using different shutil methods. How to Round to Two Decimals in PythonThis article introduces how to round to two decimals in Python. It includes round() function. How to Remove One or Multiple Keys From a Dictionary in PythonThis article introduces how to remove a key from a dictionary in Python. It includes pop() function and del keyword. How to Sort Dictionary by Key in PythonPython dictionary is unordered by default. We use the OrderedDict data type that records the element's order inserted in the dictionary and the sorted function to arrange them in ascending order. How to Read CSV to List in PythonThis article introduces how to read csv into list in Python. How to Remove the Last Character From String in PythonPython provides the support to remove the last character from string and a specific number of characters by using the slicing method, for() loop, and regex method. How to Find the Index of an Item in Python ListIn Python, elements are accessed in different ways using indexes. To access the first, last, and repeated element's indexes, index(), for loop, and list comprehension methods are used. How to Get Filename From Path in PythonThis tutorial will demonstrate different methods in Python to extract the filename from a file path, including os.path.split(), os.path.basename(), ntpath.basename(), and pathlib.Path.name. How to Replace Multiple Characters in a String in PythonThis article demonstrates how to replace multiple characters in a string in Python How to Find Duplicates in a List in PythonIt demonstrates how to find duplicates within a list in Python How to Write List to CSV in PythonA csv file can be written using Python list values. Methods like csv.writer(), writerow(), pandas, and numpy libraries are used for this purpose. How to Print Colored Text in PythonThis article demonstrates how to print colored text in Python How to List the Alphabet in PythonThis article demonstrates how to list all the alphabet in Python