Show Menu

Exam 1 Crip Sheet

math functions and errors

// whole # division
sytax -error in code form
a+=1 -> a=a+1
% find the remainder
semantic -error in logic
a/=1 -> a=a/1
** read right to left
/ always gives a float
x%y = x-y*(x//y)
{:.xf} -round float to x decimals points

Numerical functions

abs() -gives absolute values
int() -turns object to integer
float() -turns object to float
-round­(nu­mbe­r,what to round to)
-max() -finds max in list
min() -finds min in list

Import Math

math.pi is pi
math.s­qrt(x) -takes square root of x
math.e is e
math.c­eil(x) -returns smallest integer greater than x
math.t­runc(x) -removes decimal values from x

String manipu­lation

\n -end current line and start new
\t -creates a "­tab­"
\' or \" -doesnt interpret as string delimiter
\\ -true backslash
, creates defaut space of 1. can be use with all object types
+ creates no space. Cant be use to put together string and integer (or float)
string.lo­wer() -turns all letters to lowercase
string.up­per() -turns all letter to uppercase­pit­alize() -only first letter in string is uppercase
string.ti­tle() -first letter of every word is uppercase­pla­ce(­string you want to replace, what you replace with)­nd(what you want to find)
gives number of location in string
returns -1 if it cant find­unt­(what you want to count)
will give number counted
returns 0 if nothing to count­rip­(what you want to remove)
sep="" -used to change default space betwen objects seperated by ,

Variables and object intera­ctions

Variables start with letter or _
Variables can't have spaces
string and integers cant be added
string and sting cant be multiplied

Lexogr­aphical Order

Uppercase < Lowecase
a < b


len(tuple) -gives the # of objects in a tuple
cant update a tuple
tuples and strings are immutable
tuples can be added
ex r=(1,1)

Boolean Logic

If, elif, and else must all end with :
any commands following must be indented
can us <, <=, >, >, >=, ==, or !=
!= is for not equal to
cant use = since that is for variable assignment
output values are only true or false


def functi­on_­nam­e(V­ari­able):
every line which comes below is indented
can end with return statement to return a variable

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi


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