how do you do an if statement with python
dragonhunter630 (5)

how do you do an if statement with python

You are viewing a single comment. View All
ArchieMaclean (932)

Like this:

if something:
  # this will execute if "something" is true
  print("something is true")
elif somethingelse:
  # this will execute if "something" is false, but "somethingelse" is true
  print("somethingelse is true")
else:
  # this will execute if neither "something" nor "somethingelse" is true
  print("nothing is true")

You can add as many elif statements as you want.

Please mark this as the answer if it solved your problem :)

ArchieMaclean (932)

@ArchieMaclean you can replace something and somethingelse with any comparison, e.g.

if x>10:
  # blah
elif x>5:
  # blah
else:
  # blah