sweigart chapter 3 Flashcards

1
Q

function

A

like a mini program within a program. it lets you group code that gets executed multiple times.

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

def statement

A

defines the function.

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

body of the function

A

the code that follows the def statement. it is executed when the code is called.

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

deduplicating

A

means getting rid of duplicated or copy-and-pasted code. doing this makes your program shorter, easier to read, and easier to update. if you duplicate and ever decide to update, you have to change the code everywhere you copied it.

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

arguments

A

the values that are passed when a function is called. they are shown between parentheses.

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

parameters

A

variables that contain arguments. when a function is called with arguments, the arguments are stored in parameters. this stored value will be forgotten once the function returns.

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

return value

A

the value that a function call evaluates down to.

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

return statement

A

allows you to specify what the return value should be when creating a function using a def statement. it consists of (1) the return keyword and (2) the value or expression that the function should return.

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

None value

A

represents the absence of a value. it is the only value of the NoneType data type. it must be typed with a capital N. Python adds return None to the end of any function definition with no return statement. it is similar to how while and for loops implicitly end with a continue statement.

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

keyword arguments

A

identified by the keyword put before them in a function call. they are often used for optional parameters.

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

end keyword argument

A

two outputted strings automatically appear on separate lines because the print() function automatically adds a newline character. the end keyword argument is used to change the newline character to a different string.

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

sep keyword argument

A

when you pass multiple string values to print(), the function will automatically separate them with a single space. you could replace the default separating string by passing the sep keyword argument a different string.

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

call stack

A

the current function to be executed is always on top of the stack. it is how Python remembers where to return the execution after each function call. Python remembers which line of code called the function so that the execution can return there when it encounters a return statement. if that original statement called other functions, the execution would return those function calls first before returning to the original function call.

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

frame object

A

store the line number of the original function call so that Python can remember where to return. Python creates a frame object on the top of the stack if a function is called. when a function call returns, Python removes a frame object from the top of the stack and moves the execution to the line number stored in it. frame objects are always added and removed from the top of the stack and not from any other place.

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

local variables

A

parameters and variables that are assigned in a call function. they exist in that function’s local scope. they are also stored in frame objects on the call stack.

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

global variables

A

variables that are assigned outside all functions. they exist in the global scope. a variable cannot be both local and global.

17
Q

scope

A

can be thought of as a container for variables. when a scope is destroyed, all values stored in the scope’s variables are forgotten.

18
Q

global scope

A

there is only one and it is created when your program begins. when your program terminates, the global scope is destroyed and all its variables are forgotten.

19
Q

local scope

A

created whenever a function is called. any variables assigned in the function exist within the function’s local scope. when the function returns, the local scope is destroyed and the variables are forgotten.

20
Q

global statement

A

can be used to modify a global variable from within a function.

21
Q

try and except statements

A

the code that could potentially have an error is put in a try clause. the program execution moves to the start of a following except clause if an error happens. after running that code, the execution continues as normal. any errors that occur in function calls in a try block will also be caught.