Lecture 4 flash cards
midterm/final studies
what is a list ?
List [] is a collection which is ordered and changeable. Allows duplicate members
what is tuple?
Tuple () is a collection which is ordered and unchangeable. Allows duplicate members
what is set?
Set {} is a collection which is unordered and unindexed. No
duplicate members
what is dictionary ?
Dictionary {} is a collection which is unordered and changeable. No duplicate members.
are list mutable ?
yes
are tuples mutable ?
noooooooooooo
does each data type has it own method ?
yes
how to call a function in python
to call a function, use the function name followed by parenthesis
what are arguments ?
Arguments are specified after the function name inside the parentheses. You can add as many arguments as you want, just separate them with comma
how many types of arguments are there ?
4 types
default arguments
required arguments
keyword arguments
variable number of arguments
what is a default value ?
default value are those that take a default value if no arguments values are passed during the function call. You can assign this default value by with the assignment operator
what is a required argument ?
the required arguments of a UDF are those that have to be there. These arguments need to be passed during the function call and in precisely the right order.
what is a keyword arguments ?
if you want to make sure you call all the parameters in the right order, you can use the keyword arguments in your function call. You can use these to indentify the arguments by their parameter name.
what is a variable number of arguments ?
In cases where exact number of arguments are not known to pass to a function, you can use the following syntax with args or a before the parameter name in the function definition.
*args allows you to pass varying number of positional arguments.
the *args will give you all the function parameter as a tuple. This way the function will receive a tuple of arguments, and can access the items accordingly.
what type of file is module file ?
module file is (.py) containing functions or code that can be included in ones application
how are modules accessed in python ?
they are accessed using import
how can a particular function from subset of function can be accessed.
modulename.subfuncsname.functionname()
* Example: numpy.linalg.det(A) # return the determinant of matrix A
what is the keyword to only import only parts from a module ?
, by using the ““from”” keyword
from mymodule import my_div
r=my_div(15,3)
print (r)
When importing using the from keyword, do not use the module name when referring to elements in the module. Example: my_div(), not mymodule.my_div()
how do explicitly import just the names you need ?
from module import name
#Then use name in your program