How to Print a Newline in Python
The “\n” is a newline special character called an escape character that moves the cursor to the beginning of the…
How to Convert an Integer to Character in Python
Python does not have a character data type. Instead, it has a string data type, and you can represent a…
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()…
How to a Read Binary File in Different Ways in Python
Reading a binary file is like reading a normal file using the open() function. We just need to change the…
How to Pretty Print JSON in Python
There are often times when the JSON data you are getting is hard to read and cluttered. We need to…