Skip to content

Python Cheat Sheet

  • Python terminal: python3 in cmd.
  • Comments: # at the start of any line.
  • Print: print("Stay Safe…)
  • Indentation: must be followed.
num = 5
print(num)
returns 5
type(num)
<class 'int'>
num = 5.0
print(num)
returns 5
type(num)
<class 'float'>
greet = "Hello user"
print(greet)
returns: 'Hello user'
type(greet)
<class 'str'>
is_available = True
print(is_available)
returns: True
type(is_available)
returns: <class 'bool'>
num = None
print(num)
returns: None
type(num)
returns: <class 'NoType'>

+ - * / % ** // = += -= *= /= == != > < >= <= and or not

a = 6
b = 2
a + b
returns: 8
a - b
returns = 4
a / b
returns: 3
a * b
returns: 12
a ** b
returns: 36
a = 7
b = 3
a % b
returns: 1
a // b
returns: 2
a =- 5
b = 2
a > b
returns: True
a < b
returns: False
a == b
returns: False
a >= 5
returns: True
b <= 1
returns: False
a = 10
b = 2
a == 2 and b == 10
returns: False
a == 10 or b == 20
returns: True
not(a == 10)
returns: False
not(a == 2)
returns: True
number = 5
if number == 10:
print("Number is 10")
elif number < 10:
print("Number is less than 10")
else:
print("Number is more than 10")

Returns: Number is less than 10

is_available = True
f is_available:
print("Yes it is available")
else:
print("Not available")

Returns: Yes it is available

is_available = True
if not is_available:
print("Not available")
else:
print("Yes it is available")

Returns: Yes it is available