CH 5: Functions Flashcards

1
Q

Function

A

A group of statements that exists within a program for the purpose of performing a specific task.

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

Benefits of Modular Programming

A
  • Simpler Code
  • Code Reuse
  • Better Testing
  • Faster Development
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Void Function

A

A function that executes the statements it contains and does not return a value back to the part of the program that called it.

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

Value Returning Function

A

Executes the statements it contains, then returns a value back to the statement that called it.

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

Function Definition

A

The code for a function.

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

Python Function Naming Rules

A
  • Cannot use a Python keyword.
  • Cannot contain spaces.
  • First character must be one of the letters a through z. A through Z, or an underscore.
  • After the first character you may use the letters a through z or A through Z, the digits 0 through 9, or underscores.
  • Uppercase and lowercase characters are distinct.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

General Format of a function definition.

A

def function_name():
statement
statement
etc.

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

Function Header

A
  • First line of a function definition.
  • Begins with the keyword def, followed by the name of the function, followed by parenthesis, followed by a colon.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Block

A

A set of statements that belong together as a group.

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

Function Call

A

When a function is called, the interpreter jumps to that function and executes the statements in its block. Then, when the end of the block is reached, the interpreter jumps back to the part of the program that called the function, and the program resumes execution at that point.

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

Main Function

A

The function that holds the mainline logic and calls the program’s other functions, as needed.

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

Top-Down Design

A

A commonly used technique for breaking and algorithm down into functions.
- The overall task that the program is to perform is broken down into a series of subtasks.
- Each of the subtasks is examined to determine whether it can be further broken down into more subtasks. This step is repeated until no more subtasks can be identified.
- Once all of the subtasks have been identified, they are written in code.

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

Hierarchy Charts

A
  • Used to visually represent the relationships between functions.
  • Also known as a Structure Chart.
  • Shows boxes that represent each function in a program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Pass Keyword

A
  • Facilitates the creation of empty functions.
  • Ignored by the Python interpreter.
  • Can be used as a placeholder anywhere in Python, not just functions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Local Variable

A
  • A variable that is created inside a function and cannot be accessed by statements that are outside the function.
  • Different functions can have local variables with the same names because the functions cannot see each other’s local variables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Variable Scope

A

The part of the program in which the variable may be accessed. A variable is visible only to statements in the variables scope.

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

Argument

A

Any piece of data that is passed into a function when the function is called.

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

Parameter Variable

A

A variable that receives an argument that is passed into a function.

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

Passed by Position

A

When the first argument is passed into the first parameter, the second argument is passed into the second parameter, and so forth.

20
Q

Pass by Value

A

A form of argument passing that is used in Python, where a function cannot change the value of an argument that was passed to it.

21
Q

Keyword Argument

A

Function calling syntax that specifies which parameter, by name, that an argument is to be passed into.

22
Q

Keyword Only Parameter

A
  • Parameter list that will only accept keyword arguments.
  • Everything after *
23
Q

Positional-Only Parameters

A
  • Will accept only positional arguments
  • Everything before` /
24
Q

Default Argument

A

When a default argument is provided for a parameter, you can call teh function without explicitly passing an argument into the parameter.

25
Q

Global Variable

A

Accessible to all the functions in a program file.

26
Q

Reasons not to use global variables:

A
  • Make debugging difficult
  • Functions that use global variables are dependent on those variables.
  • Make programs hard to understand.
27
Q

Global Constant

A
  • A name that references a value that cannot be changed.
  • Permissible to use, unlike global variables.
28
Q

Value Returning Function

A

A function that returns a value back to the part of the program that called it.

29
Q

Standard Library

A

Pre-written functions (library functions) that the developer does not have to write.

30
Q

Module

A

A Python source code file that can be imported into other Python programs.

31
Q

Black Box

A

Any mechanism that accepts input, performs some operation that cannot be seen on the input, and produces output.

32
Q

Pseudorandom Numbers

A

A number that is seemingly random but is actually calculated.

33
Q

Seed Value

A

The number that is used to initialize the formula that produces random numbers.

34
Q

Boolean Functions

A

A function that returns either True or False.

35
Q

Modularization

A

Writing a program in such a way that each task is performed by a separate function.

36
Q

What is a function?

A

A group of statements that exist within a program for the purpose of performing a specific task.

37
Q

What is meant by the phrase “divide and conquer”?

A

A large task is divided into several smaller tasks that are easily performed.

38
Q

How do functions help you reuse code in a program?

A

If a specific operation is performed in several places in a program, a function can be written once to perform that operation, then be executed anytime it is needed.

39
Q

How can functions make the development of multiple programs faster?

A

By reusing the code.

40
Q

How can functions make it easier for programs to be developed by teams of programmers?

A

The team and work can be broken down to work on different functions.

41
Q

A function definition has what two parts?

A
  • Function Header
  • Block
42
Q

What does the phrase “Calling a function” mean?

A

The interpreter jumps to that function and executes the statements in its block.

43
Q

When a function is executing, what happens when the end of the function’s block is reached?

A

The interpreter jumps back to the part of the program that called the function, and the program resumes execution at that point.

44
Q

Why must you indent the statements in a block?

A

Indentation is how the interpreter understands block grouping.

45
Q

What is a local variable? How is access to a local variable restricted?

46
Q

What is a variables scope?

A

The part of the program in which the variable may be accessed.

47
Q

Is it permissable for a local variable in one function to have the same name as local variable in a different function?

A

Yes, that is variable overloading. As long as all of the variables are local to their functions, that is permissable.