Exam 1 Crip Sheet
|
// 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
|
||
|
abs() -gives absolute values
|
|
|
pow(number,exponent)
|
|
|
int() -turns object to integer
|
|
|
float() -turns object to float
|
|
|
-round(number,what to round to)
|
|
|
-max() -finds max in list
|
|
|
min() -finds min in list
|
|
math.pi is pi
|
|
|
math.sqrt(x) -takes square root of x
|
|
|
math.log(base,variable)
|
|
|
math.e is e
|
|
|
math.ceil(x) -returns smallest integer greater than x
|
|
|
math.trunc(x) -removes decimal values from x
|
|
\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.lower() -turns all letters to lowercase
|
||
|
string.upper() -turns all letter to uppercase
|
||
|
string.capitalize() -only first letter in string is uppercase
|
||
|
string.title() -first letter of every word is uppercase
|
||
|
string.replace(string you want to replace, what you replace with)
|
||
|
string.find(what you want to find)
|
gives number of location in string
|
returns -1 if it cant find
|
|
string.count(what you want to count)
|
will give number counted
|
returns 0 if nothing to count
|
|
string.strip(what you want to remove)
|
||
|
sep="" -used to change default space betwen objects seperated by ,
|
||
|
Variables start with letter or _
|
|
|
Variables can't have spaces
|
|
|
string and integers cant be added
|
|
|
string and sting cant be multiplied
|
|
Uppercase < Lowecase
|
true
|
|
a < b
|
true
|
|
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)
|
|
|
r+s=(1,1,'a','b')
|
|
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 function_name(Variable):
|
|
|
every line which comes below is indented
|
|
|
can end with return statement to return a variable
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.