Conditionals in Python
Introduction
The simplest statement in Python is pass it does nothing.
Statements come in different kinds:
-
Assignment: a = 1945.
Here we assign the value 1945 to the variable a.
In English this is called an «assignment statement»
-
Output: print(b);. We print the value of the variable b to the screen.
In English this is called an «output statement»
-
Declaration: int x
It exists only in compiled languages (
C,
C++,
Java,
Go and others) but it is useful to know about it.
In English this is called an «statement declaration»
if elif else
a = 1961b = 1945if b > a:print("b is greater than a")elif a == b:print("a and b are equal")else:print("a is greater than b")Article author: Andrei Olegovich