Show Menu
Cheatography

Python Language And Syntax Cheat Sheet (DRAFT) by

A schematic Python reference

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Variable Assign­ments

integer = 1
string = "­str­ing­"
unicod­e_s­tring = u"un­icode string­"
mulri_­lin­e_s­treing = """multi-line
string
"""
tuple = (element1, element2, element3, ...)
list = [element1, element2, element3, ...]
dictionary = {key1: value1, key2: value2, key3: value3, ...}
dictio­nar­y[key] = value
dictio­nar­y.g­et(key, defaul­t_i­f_n­ot_­exists)
class_­ins­tance = class_­nam­e(i­nit­_args)

Frequently Used Built-In Types

True
False
None
str
unicode
int
loat
list
dict
Other than True, False and None, these can also be used as functions to explicitly cast a value to that type.

Functions

def functi­on_­nam­e(arg1, arg2, keywor­d1=­value1, keywor­d2=­value2, ...):
    <function_body>
    return retrun­_value
e.g.
def my_function(x,y,z=0):
    sum = x + y +z
    return sum
my_fun­cti­on(1, 2) --> 3
my_fun­cti­on(1, 2, 3) --> 6
my_function(1, 2, y=4) --> 7