How do I make this line of code shorter?

0 votes
asked Oct 31, 2018 by Ender (130 points)
if x == "hello":


elif x == "hi":


I want to make the if hi and if hello shorter into if hi and hello

3 Answers

0 votes
answered Oct 31, 2018 by Kevin Sweny (190 points)
If you wanted the logic to be if x == hi, OR hello

You would use if ((x == "hello") || (x x == "hi")), the operator for OR is ||
commented Dec 11, 2018 by Tomas Z (180 points)
operator || is not in python, but you can use      or      keyword  instead.
+1 vote
answered Nov 3, 2018 by Prabhat Mishra
if(x=='hello' or x=='hi'):

+3 votes
answered Jan 4, 2019 by Raphael SCHMITZ-DU MONT (200 points)
another way would be

if x in ['hello', 'hi']:

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.