Oct18_round Flashcards
difference between set update and set union
update changes the set it is called on, i.e. s.update(s1) will change s by adding s1 to it. whereas union will create a new object containing both s and s1 without modifying either.
what are the 3 types of comprehension in python
list, dict and set
The default argument in a python function is evaluated once. Give an example.
def f(a, L=[]): L.append(a) return L f(1) L = [1] f(2) L = [1,2] etc
if you have a list of argument L but the function f needs them unpacked, i.e. as induvidual elements, what is the syntax?
f(*L)
if you have a dictionary of arguments and a function needs them induvidually, what is the syntx
function(**dictionar_args)
what function shows all the attributes of an object (or all the names in the object’s namespace)
dir(object)
what is the difference between the global and nonlocal keyword when used before a variable name
global means “place this variable in the global scope and if it’s already there, use it.”
nonlocal means “place this variable in the nearest enclosing scope and if it’s not there flag an error”
if python finds “none” against the name of a module in sys.path, what does it do? When it does not find the path itself what does it do?
if it is mapped to none - modulenotfound exception is raised. Otherwise it cointinues searching.
what is the command to upload a python package to pypi so everone can use it?
python setup.py reigster sdist upload
what is the name and type of special variable that you define in __init__.py which specifies which modules are loaded into the namespace when the enclosing package is created.
__all__ and type is list
how do you create a tuple with a single element
tup = (“singleton”,) #the races are optional
what is the onlynamespace that remains from beginning to end in a python script?
The namespace containing the built in names. This is loaded when the python interpreter starts up.
what is the lifetime of a function namespace?
created when a function starts and destroyed when the function exits
when is the global namespace created?
when the module is read in
what are the different types of expressions?
list, set and dict