Python yield vs. return: What is the Difference?

Two keywords that often confuse beginner Python programmers are yield and return. Both of these keywords have a role to play in Python functions, but they serve different purposes. The return keyword is used to immediately return one or more values from a function in Python. The yield keyword when used in a function returns … Read more

How to Implement the Binary Search Algorithm in Python

Binary search is a well-known computer science algorithm you can implement in many languages including Python. It is an algorithm that allows finding elements in a sorted array. It is frequently brought up in programming competitions and technical interviews. You should always use existing libraries when performing binary search in Python or any other language. … Read more

How to Execute a Shell Command in Python [Step-by-Step]

Knowing how to execute a shell command in Python helps you create programs to automate tasks on your system. There are multiple ways to execute a shell command in Python. The simplest ones use the os.system and os.popen functions. The recommended module to run shell commands is the Python subprocess module due to its flexibility … Read more

Python args And kwargs Explained: All You Need to Know

Using args and kwargs can be quite cryptic especially if you are new to Python. Let’s find out together all you need to know about them. What are *args and **kwargs? *args and **kwargs allow to pass an arbitrary number of positional arguments (*args) and keyword arguments (**kwargs) to a Python function. You can use … Read more