Python Functions are First-class Objects In Python functions are first-class objects which means that functions can be assigned to variables or passed as an argument for another function in the same manner as primitive data types and objects. For example, in the following code, the function operator has three parameters operation, x, and y. While...
What is Python __name__ == "__main__"?
You might have seen the Python line if __name__ == "__main__": in several code examples and wonder what does it do? Many other programming languages such as Java or C/C++ require a main function as the starting point for an application. However, in Python you can type some lines of code in a file, and...
Python Course #18: Your First Sorting Algorithm (Insertion Sort Explained)
With the knowledge of Python functions and algorithms, we are ready to write our first sorting algorithm and also take a closer look at how fast it runs. What is a Sorting Algorithm A sorting algorithm’s purpose is to reorder a list of elements based on a comparison criterion. This criterion is usually a less...
Python Course #16: Functions
Up until now you have used a lot of functions already, most prominently the print(...) function. Now it is time to write your own functions in Python. What is a function in Programming? A function is a piece of code that is responsible for carrying out a task. Functions encapsulate several lines of code into...
Python Course #14: User Input
Now that you know how to use for and while loops in Python, you can start getting input from outside of your program. In this article, you will learn how to capture a user’s input and build a small calculator in Python. Python input() Python provides a straightforward way to get input from a user...
Python Course #13: Loops
Up until now, the control flow of your programs was only from top to bottom. However, when writing more complex programs, it is often necessary to execute a specific piece of code several times in a row, and this is where loops come into play. Python While Loops Python (and many other programming languages) offers...
Change Windows 10/11 Display Resolution with a Python System Tray Application
Suppose you have to change your display resolution reasonably often. In that case, it can be a bit tiring to open the Windows display settings, choose the preferred resolution and confirm that you want to keep this resolution. But you can circumvent the Windows display settings with a small Python script. TL;DR You can find...