Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine if conditions in Python

Tags:

python

Does this exist in Python? I want to combine an If statement that is very repetitive.

# ORIGINAL IF STATEMENT
if a < 100 and b < 100 and c < 100:
    #pass

# I KNOW THIS IS WRONG, I JUST WANT TO KNOW IF THERE IS A WAY TO MAKE THE IF CONDITION SHORTER
if [a,b,c] < 100:
    #pass
like image 625
Fermin Arellano Avatar asked Jul 20 '26 05:07

Fermin Arellano


2 Answers

You can use the built-in all():

if all(item < 100 for item in [a, b, c]):
like image 195
alecxe Avatar answered Jul 22 '26 17:07

alecxe


You can also use the built-in max():

if max(a, b, c) < 100:
like image 27
TigerhawkT3 Avatar answered Jul 22 '26 18:07

TigerhawkT3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!