Trick To Simplify IF In Python

Shweta Lodha
2 min readAug 10, 2022

Using conditionals or say IF-ELSE statement is quite common when developing any application and based on the programming language, the syntax to handle such conditionals varies but the underline concept remains the same.

In this article, I’ll show you how to write an IF statement in Python to check if a given item is present in the collection or not.

Have a look at the traditional way to achieve the same:

fruits = [‘apple’,’orange’,’banana’,’mango’]
fruit = ‘mango’
if(fruit==’apple’ or fruit==’orange’ or fruit==’banana’ or…

--

--