mercredi 7 mars 2018

how to shorten if statements with or or and operators in python and java [duplicate]

This question already has an answer here:

currently if i want to check if a number is equal to other numbers in python I'd do it as such

if num1 == num2 || num1 == num3 || num1 == num4:
    # code here

and in java

if (num1 == num2 || num1 == num3 || num1 == num4) {
    #code here
}

What I'd want is something like

if num == num2 || num3 || num4:
    #code here

Is there any way to shorten these statement?

Aucun commentaire:

Enregistrer un commentaire