Show Menu

COMP 2001 Cheat Sheet by

COMP 2001 cheat sheet for coding language python

Order Of Precedence

Parent­hesis ()
Function Call f(args..)
Indexing []
Exponents **
Unary plus, Unary minus +x, -x
Multip­lic­ation, division, floor division, remainder *, /, //, %
Addition and subtra­ction +, -
Identity operators, membership operators (in, not in, is, is not)
Equality Operators !=, ==
Comparison operators <, <=, >, >=
Boolieans ( NOT, AND, OR)

Files, Lists, Loops, selections

open file under (name, w/r)
foname.wr­ite­(st­r(l­ist[i]) + "\n or ,")
reads rows of text in file
reads columns in file
closes file
Start, stop, stride
while i > var:
make sure to add :
Single outcome decision structure
if ...
Double outcome decision structure
if, else
Chained decision structure
if, elif, elif, else
Nested decision structure
if, (indent) if, else, (outdent) else


New line
Tab line
Chained IF structure
a set of conditions that allows for only one block of code to run: if...e­lif...e­li­f...else
the process by which strings are joined together (uses an overloaded + operator)
Implicit data type
variable = 5, variable = 5.0
Explicit Data Type
variable = int(5.0), variable = string(5)
De Morgans Laws
not (x and y) == (not x) or (not y) not (x or y) == (not x) and (not y
Definite Loop
a loop that repeats a specified number of times; also called a counted loop
Indefenite Loop
loop that repeats an unspec­ified number of time based on the condition (condi­tional loop)
Infinite Loop
a loop that never stops. Usually the result of an error in the internal change­/read
Sentinel Loop
continues to process data until reaching a special value that signals the end.
function (Void and Value-­Ret­urning)
def nameOf­unction (optional parame­ters, default parame­ters, etc) : # code as needed # that is indented # return optional value
a value returning function that indicates how long an object is (ie how many characters in a string or how many items in a list)
prints largest ASCII value
prints lowest ASCII value
sorts in ASCII order
In Python, a value returning function that adds up all the numerical items in a list.n Excel, a value returning function that alls up all the numerical values in a range.
value-­ret­urning function
a function that does its processes to produce a result that is returned to the main program
void function
a function that performs processes, but does not create­/return a result
a descri­ption of the location within code and of a time when that code is being executed, where/when the computer can access­/know about that code


turns var lowercase
turns var uppercase
swaps the case or letters (upper to lower, vice versa)­pit­alize
capita­lizes first letter
a void method that is part of all lists that will add x to the end of that list
a value returning method that is part of all list objects, that produces the location (index number) of the value x
a value returning method that all lists have that will produce the number of times x occurs in the list
a void list object method that deletes the first instance of the value x from the list
list.i­nse­rt(­index, x)
a void method that is part of all list objects that inserts the value x at index
a void list object method, one that takes the list and sorts in in ascending order
a value returning list method that produces the value of the item at x. If x is left blank, the default is -1, the last item's value
logic Error
an error in the code that does NOT prevent the code from running, but stems from an incorrect solution that produces unintended or undesired output or other behavior
Index Error
A type of run time error (only happens when the program runs) when the code is asked to work with an index location that is larger than the length of the list or string
Name Error
a Run-time error in the code where a named thing (like a variable or a function) is invoked and/or used before it is defined.
run-time Error
an error that occurs only when the program is run - usually due to input/­output and data type conflicts
syntax error
an error in the code that prevents it from running where the code does not follow the rules of spelling, punctu­ation and/or grammar
Type Error
A kind of Run-time error where the variable types do not match the function's or mathem­atical operator's requir­ements.


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Python 3 Cheat Sheet by Finxter