The false bible of commands Flashcards
what does random() do?
random real number between 0 and 1 (not inclusive of 1, but 0 works)
what does randint() do?
returns random integer between a and b INCLUSIVELY (and doesnt work when not provided a range)
what happens if you get an undefined error?
you redefined a core python function/something and is now uncallable, reset python immediately
are while true loops allowed?
NAH
.title()
capitalizes first letter, lowercases all others
what does the keyword del do?
deletes a variable from memory
repr()
returns exactly what string you put in, NOT including quotations (but also performs actions like 1+3 within it, and if you do a list like [1, 4, 2] it wont capture the weird space, and also always single quotes for everything even if you do repr(“hiello”)
abs()
returns absolute value of smth, either in or float or 0 or 1 when used on a boolean, part of standard python (no import needed)
ord()
standard python, converts string input to integer equivalent in unicode code
chr()
standard python, converts to single letter string from unicode code input
len()
standard python, returns length of any iterable data sequence (tuple, string, list)
del
keyword in standard python, deletes variables and elements of mutable data sequences, alterring the sequence itself (deletes parts of lists if you want it to and lessens length by 1 every time)
list()
standard python, typecasts something iterable to a list (does not work on floats or ints or booleans) (tuples and strings work though)
shuffle()
random module, randomly organizes items in data sequence. original object is mutated, DOES NOT CREATE NEW OBJECT
shuffle(x)
in
standard python keyword, returns boolean True or False if x is found anywhere in data sequence y (does not work on ints or floats or bools) (works on tuples and strings)
x in y = True or False
max() and min()
standard python, returns highest and lowest value in data sequence (even works to compare booleans and strings though you prob dont need that)
sum()
standard python, sums numbers in list (works on everything BUT strings)
sum(x)
mean()
statistics class, CANNOT be used on strings, returns average of data sequence elements
median()
statistics class, can be used on strings, returns middlemost element of data sequence
mode()
statistics class, can be used on strings, returns most common element of data sequence
multimode()
statistics class, mode but returns list and list can contain multiple “most common elements” of any data sequence
reverse()
list.reverse()
ONLY WORKS ON MUTABLE DATA SEQUENCE TYPES
reverses all elements in sequence
append
list.append(x)
adds ONE item to end of MUTABLE data sequence
pop
x.pop(i)
removes item at INDEX i from MUTABLE sequence x, UNLIKE OTHER SEQUENCE METHODS returns item removed
no index = defaults to i = -1, or last item in the list
insert
x.insert(2, y)
inserts y into x at index 2 of MUTABLE data sequence
DOES NOT DELETE PREVIOUS ITEM AT THAT INDEX
extend
x.extend([y])
adds list y’s elements to end of MUTABLE sequence x
append would have just added a nested list
count
list.count(x)
returns the number of occurrences of x in a list (works on all data sequences)
index
x.index(y)
returns the index of y within x (works on all data sequences)
remove
x.remove(y)
removes item y in x (NOT index location), works on MUTABLE data sequence
clear
x.clear()
turns mutable sequence x into empty list
sort
ONLY WORKS ON LISTS
list.sort()
sorts list by ascending order (by default), or by descending if reverse flag set to true
sorts list IN PLACE, does not return anything
ex.
numlist.sort(reverse=True)
sorted
sorted(numlist)
RETURNS sorted list, does not change list itself
works on any iterable