Blog
How to Delete File If It Exists in Python
Our primary goal is to remove a file if it exists; if it does not, we need to avoid the…
How to Convert Char to Int in Python
Python does not have a “char” data type, unlike other languages. But characters are just strings of length 1. When…
How to Print a Newline in Python
Here are three ways to print a newline in Python: Explicitly include “\n” in the print() function Implicitly add “\n”…
How to Convert an Integer to Character in Python
Python provides a built-in function called the “chr()” to convert an integer to a character. It accepts an integer argument and…
How to Define a Variable inside If Statement in Python
The developer should not directly define a variable inside the “if statement” because if you are using that variable outside…
Printing a List of Files in Directory and Subdirectories in Python
Whether we are searching for a specific file or building directory trees, we need to access the file system programmatically,…
How to Implement Touch using Python
To implement touch in Python, you can use the pathlib module’s “Path.touch()” method. It will create any file in any…
How to Create File If It Does Not Exist in Python
Here are three ways to create a file if it does not exist in Python: Using with open() method with…
How to Read Text File into List in Python
When reading a file into a Python list, always use the with open(…) context manager to open the file in read mode,…
Creating a Filename Containing Date or Time in Python
The most efficient way to create a filename containing date or time, use f-strings (Python 3.6+) with datetime.now() and .strftime()…