Functions, Tuples, Dictionaries, Exceptions, and Data Processing Flashcards

1
Q

What is decomposition?

A

Dividing he code into well-isolated pieces and encodes each of them in the form of a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two conditions of creating a function?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where do functions come from ?

A

python
modules
code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two important catches of functions?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What makes parameters different to variables?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between an argument and a parameter?

A

parameters live inside functions (this is their natural environment)
arguments exist outside functions, and are carriers of values passed to corresponding parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is shadowing?

A

When a variable has the same name as a parameter

(parameter is define only inside the function)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is positional parameter passing?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is keyword argument passing?

A

The meaning of the argument is dictated by its name, not by its position

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the rule for mixing key word and positional argument passing?

A

you have to put positional arguments before keyword arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are two uses of None?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Is a variable created outside any function visible inside the functions?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the global keyword do?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is recursion?

A

recursion is a technique where a function invokes itself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a sequence type?

A

a sequence is data which can be scanned by the for loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is mutability?

A

Mutable data can be freely updated at any time

Immutable data cannot be modified in this way.

17
Q

How do you create a one element tuple?

A

one_element_tuple_1 = (1, )
one_element_tuple_2 = 1.,

If you want to create a one-element tuple, you have to take into consideration the fact that, due to syntax reasons (a tuple has to be distinguishable from an ordinary, single value), you must end the value with a comma:

18
Q

Output of:

my_tuple = (1, 10, 100)
t1 = my_tuple + (1000,10000)

A

(1, 10, 100, 1000, 10000)

19
Q

Things to remember about dictionaries?

A

Keys must be unique
dictionary is a one way tool can look for values of keys but not keys of values
dictionaries don’t preserve the order of data as it is meaningless

20
Q

For loops for dictionaries?

A

for key, value in dictionary.items():

for key in dictionary.keys():

for value in dictionary.values():

21
Q

What happens if an error occurs between the try and except branches?

A

The program will not be terminated but it will jump to the except branch and no other part of the try will be executed

22
Q

Where must the default expect branch be?

A

At the end

23
Q

What is Zero division error?

A

when you try and divide by 0 using /, //, or %

24
Q

What are the types of exceptions?

A

ZeroDivisonError
ValueError
TypeError
AttributeError
SyntaxError

25
Q

Be careful: keywords cannot be used as variables/arguments!!!!!!

A
26
Q

What is a ValueError?

A

When a function receives an argument o a proper type but the value is unacceptable int(‘the’)

27
Q

What is a TypeError?

A

When you try to apply a data who’s type is cannot be accepted in the current context