Python
Whitespaces matter
E.g.
Product = 3 ** 3 (Power)
Product = 3 * 3 (Multiplication)
When printing a string but an apostrophe is present, python stops the string there, thus
String = “There isn\’t blab la”
print {variable name}
print len(variable name) = gives length of string
print variablename.lower() = uncapitalizes string
print variablename.upper() = capitalises string
print str(variablename) = sets a non string into a string
Dot Notation
Only used for string variables, however, functions such as len and str don’t need it as they can deal
with other data types
print "Spam " + "and " + "eggs" Concatenating strings
print "The value of pi is around " + str(3.14)
String Formatting
Date and Time
Control Flow and Data Input
And Or Not
not True = False
If statements and stuff
Elseif = elif in python
Functions
def functioname(argument):
import math
importing only a certain function from a module
Import these way in order not to have to type math.sqrt all the time. However, it is better to have
math.sqrt as sqrt may be a function name of your own coding.
max(), min(), abs()
type() – returns the type of the data
Lists
Listname = [“blablabal", something]
Lists don’t have a fixed length
include index of item after the last item u want
Finding index then inserting a string into
the list
For Loops
appending numbers into
another list then sorting it
key1 points to 1 and so on
Appending into a
dictionary
Deleting a key from a dictionary
Removing from a list
For loop to print dictionary
Lists in Lists
Add zip to include two lists
For-else
Remove the break to initialise the else statement!
Checking int: