One of the most common ways to debug is by using print() functions in Python.

They are so commonly used all over the place that you may even end up seeing them in code that is included in production.

One thing that not a lot of people know is that you can include conditions in print() functions.

Let us see this in an example. Let us assume that we want to implement a function that checks whether a number is positive or negative. We can print different one message when the input value is positive and another value when it is negative.

Let us see this in action:

def is_positive(number):
    print("Positive" if number > 0 else "Negative")  

Now, when we call this function with a positive number as a parameter, we are going to see the following printed in the console:

is_positive(3)  # Positive

That’s pretty much it. I hope you find this useful.