Functions, Tuples, Dictionaries, Exceptions, and Data Processing Flashcards
What is decomposition?
Dividing he code into well-isolated pieces and encodes each of them in the form of a function
What are the two conditions of creating a function?
- if a particular fragment of code is repeated in more than one place
- if a piece of code is so large that reading and understanding it may cause problems, split into smaller problems and implement each in form of function
Where do functions come from ?
python
modules
code
What are the two important catches of functions?
You mustn’t invoke a function which is not known at the moment of invocation
You mustn’t have a function and a variable of the same name.
What makes parameters different to variables?
parameters exist only inside functions in which they have been defined, and the only place where the parameter can be defined is a space between a pair of parentheses in the def statement;
assigning a value to the parameter is done at the time of the function’s invocation, by specifying the corresponding argument.
What is the difference between an argument and a parameter?
parameters live inside functions (this is their natural environment)
arguments exist outside functions, and are carriers of values passed to corresponding parameters.
What is shadowing?
When a variable has the same name as a parameter
(parameter is define only inside the function)
What is positional parameter passing?
A technique which assigns the nth argument to the nth function parameter is called positional parameter passing, while arguments passed in this way are named positional arguments.
What is keyword argument passing?
The meaning of the argument is dictated by its name, not by its position
What is the rule for mixing key word and positional argument passing?
you have to put positional arguments before keyword arguments
What are two uses of None?
when you assign it to a variable (or return it as a function’s result)
when you compare it with a variable to diagnose its internal state.
Is a variable created outside any function visible inside the functions?
YES, A variable existing outside a function has a scope inside the functions’ bodies, excluding those of them which define a variable of the same name.
What does the global keyword do?
Extends a variable’s scope in a way which includes the functions’ bodies
In other words, this name becomes global (it has a global scope, and it doesn’t matter whether it’s the subject of read or assign).
What is recursion?
recursion is a technique where a function invokes itself
What is a sequence type?
a sequence is data which can be scanned by the for loop.