if else conditional statement in python
Like any other programming or scritpting language, python also provides widely used conditional statement - if else.
What's the use of if else ? This is very common phenomenon in programming and even in our life, we have to perform some action in a specific condition or situation. In other words, perform something if a condition meets.
In programming, if a condition meet perform some specific job.
Syntax of if-else condition at below.
if <condition>:
# perform something
else:
# perform something else
Now, let's take an example. User wants to check the count of item added in his cart should not be more than 5. If count is more than 5, system should notify.
cart = ["Bread", "Eggs", "Butter", "Pan", "Salt", "Sugar"]
if len(cart) > 5:
print("Your cart has more than 5 items")
else:
print("Please proceed with payment")
Here at above code block, as cart has more than 5 items so it meets if condition, this will print the message "Your cart has more than 5 items"
THAT'S IT