Python 3#
Basics#
Data Types#
Data Type |
Examples |
---|---|
Integers |
|
Floating-point numbers |
|
Strings |
|
Lists |
|
Tuples |
|
Dictionaries |
|
Control Flow#
if
statements#
if name != 'George':
print('You are not George')
if name != 'George':
print('You are not George')
else:
print('You are George')
if name == 'Debora':
print('Hi Debora!')
elif name == 'George':
print('Hi George!')
else:
print('Who are you?')
while
Loop statements#
spam = 0
while spam < 5:
print('Hello, world.')
spam = spam + 1
for
loop#
pets = ['Bella', 'Milo', 'Loki']
for pet in pets:
print(pet)
for i in range(5):
print(f'Will stop at 5! or 4? ({i})')
Operators#
Math Operators#
Operators |
Operation |
Example |
---|---|---|
|
Exponent |
|
|
Modulus/Remainder |
|
|
Integer division |
|
|
Division |
|
|
Multiplication |
|
|
Subtraction |
|
|
Addition |
|
Comparison Operators#
Operator |
Meaning |
---|---|
|
Equal to |
|
Not equal to |
|
Less than |
|
Greater Than |
|
Less than or Equal to |
|
Greater than or Equal to |
Boolean Operators#
Operator and
#
Expression |
Result |
---|---|
|
|
|
|
|
|
|
|
Operator or
#
Expression |
Result |
---|---|
|
|
|
|
|
|
|
|
Operator not
#
Expression |
Result |
---|---|
|
|
|
|