If & Else Statements

If & Else statements

  • Control flow is controlling which lines of code run in a program

  • With conditionals such as if, else

if 5 < 6:
	print('yes 5 is less than 6')
else:
	print('this will never be printed') # in code editor will say that code is not reachable

Always going to run:

if True:
	print("this will always be printed")
else:
	print("this will never be printed")

Surrounding conditionals with paranthesies:

elephant = 800
hippo = 900
if (elephant < hippo and (3 > 2)):
	print('if statement evaluated to True')
else:
	print('if statement evaluated to False')

Last updated