How do I make this line of code shorter?

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

     print("great")

elif x == "hi":

     print("great")

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 (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 (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'):

   print("great")
+1 vote
answered Jan 4 by (160 points)
another way would be

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

    print('great')
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.
...