This is a draft cheat sheet. It is a work in progress and is not finished yet.
Data Types
Integer |
-238, 39 |
Float |
-253.23, 1.253e-10 |
String |
"Hello", 'Goodbye', "Multiline" |
Boolean |
True, False |
List |
[ value, ... ] |
Conditional Statement
if condition:
statements
elif condition:
statements
else:
statements
|
Arithmetic Operators
x + y |
add |
x - y |
substract |
x * y |
multiply |
x / y |
divide |
x % y |
modulus |
x ** y |
power |
Comparison Operators
x < y |
Less |
x <= y |
Less or eq |
x > y |
Greater |
x >= y |
Greater or eq |
x == y |
Equal |
x != y |
Different |
For loop
for i in range(start, end):
statements
|
While loop
while condition:
statements
|
Break and Continue
Break |
Go out of the loop |
Continue |
Go back to the beginning of the loop |
Function Definition
def name(arg1, arg2, ...):
statements
return expr
|
Useful functions
|
variable_name = input("something")
|
Operation on strings
|
7 |
"example1" + "example2"
|
|
|
|
"I love Python".upper()
|
|
"I love Python".lower()
|
|
Lists Basics
Create an empty list |
|
Create a list with values |
my_list = [11, "Python", 12.5]
|
Access an element |
|
Modify an element |
|
Append an element |
my_list.append(element)
|
Iterate over a list
for element in my_list:
statements
|
Create a Class
class class_name:
statements
|
The init method
def __init__(self, params):
statements
|
Objects
Creation |
variable_name = class_name(params)
|
Access of an attribute |
variable_name.attribute_name
|
Use of a method |
variable_name.method_name(params)
|
|
|
|