Lecture 8 Flashcards

1
Q

Function

A

Is a reusable block of code that can be executed on an as needed basis

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

What do we use functions for?

A

To help organize code
Make code more modular, and therefore scalable
Make debugging easier
Avoid repetition
Support code sharing

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

Function calling

A

A function is called when the program requests to run the code in the function, calling a function, interrupts the linear flow of a program the program will:
Jump to another place in the file
Execute the function code
Return back to the main part of the program where the function was called

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

Fuction syntax

A

def <function>(argument info):
<function></function></function>

<end>
<main>
<function name(arguments)>
</main></end>

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

Preliminary observations about functions

A

Function definitions must appear before function calls in the file
There can be multiple calls to the same function within a program
Arguments can be sent by value or as variables in function calls
Variables sent as arguments do not have to have the same name as the argument name in the function declaration

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

Default arguments

A

Arguments that have default values if they are admitted during a function call

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

Keyword arguments

A

Arguments referenced by name rather than position during function call

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

Preliminary observations about default/keyword arguments

A

Default arguments must appear at the end of the argument list in the function definition. Only default arguments can be omitted.
Keyword arguments must use the same argument name in the function call as the function definition. Only the last arguments in the argument list can be keyword arguments, though they can be provided in any order.

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

Functions have access to

A
  • Arguments in the function definition
  • variables defined within the function, local variables
  • variables defined in the main program before the function call global variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Functions can change

A
  • argument values and local variables
  • Global variables, but only when declared with the global keyword in the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Arbitrary arguments

A

If the number of arguments being sent to a function is variable, use a* before the argument

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

Arbitrary keyword arguments

A

If the number of keyword arguments being sent to a function is variable use a ** before the argument name

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

Mixing arguments

A

The following order must be followed in both of the function, definition and function call
1) positional arguments
2) default arguments
3) keyword argument
4) arbitrary arguments
5) arbitrary keyword

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

Return

A

Return to the function to immediately return to the function that called it and return the value that is to the right of return

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