Skip to main content

Posts

Showing posts with the label The Crazy Programmer Python One Line if Statement Python One Line if Statement The Crazy Programmer

Python One Line if Statement Gorakh Gupta The Crazy Programmer

In our daily life whenever we are trying to solve any real life problems then we may have to write some conditional statements very often. A simple if condition takes 2 or 3 lines if we want to process a statement in it. Suppose we have to write more than 10 conditions in a program. We can see it will take approx 40 to 50 lines of code where we are just repeating the things. So, python allows us to write the if conditions in a single line which is often called one liner if in Python. This will make our code more readable and less redundant. By using this functionality, we can reduce some spaces in our python code. Now we will see all the types by using which we can write a one liner if condition in python. Also Read: Python One Line for Loop First, we will see a general method of if condition and its output. # General Method for If Condition in Python num = 6 if num % 2 == 0: print("Even") Output: PS C: \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > pyt