List of Python related pages
-
Checking if a Python list is empty
There are several ways to check if a list contains any elements, such as using “if not”, the built-in len function, or comparing it to an empty array. -
Printing to Standard Error (stderr) in Python
By default, the print function prints a string to standard output (stdout), but you can specify a different output destination with the file argument. When you pass sys.stderr as this argument, the print function prints the string to standard error. You can also use the write method of sys.stderr to output, but unlike the print function, it does not automatically insert a newline. -
Python - Doing nothing with an if statement
When you don’t want to do anything in an if statement when a condition is met or not met, you can use the pass statement. -
Python - Error No module named ‘PIL’ occurs
The error ModuleNotFoundError: No module named 'PIL' occurs when the image processing library Pillow is not installed. To resolve this, install Pillow using the pip command. -
Python - Getting the Absolute Value
To get the absolute value, you can use the built-in function abs, the fabs function from the math module, and the fabs function from the cmath module. -
Python - Getting the index with a for loop
By using the built-in function enumerate, you can get both the index and the value of a list at the same time. enumerate is a built-in function that takes an iterable object (such as a list, tuple, or string) as input, assigns an index to each element, and returns a pair of the index and element. -
Python - Preventing Line Breaks with the print Function
If you don’t want to output a line break with the print function, specify an empty string for the end argument. -
Python - Wait for a specified time (sleep / wait)
To stop a program (thread) for a specified time, use the sleep function of the time module.
-
Visual Studio Code - Hide __pycache__
To hide the Python cache folder “__pycache__” and the cache file “.pyc”, add the pattern of the file/folder you want to hide to the “files.exclude” setting.