Functions Flashcards

1
Q

Calling a function

A

Ex built-in function pow(x,y)

Pow = function name
X and y are arguments passed into pow
Return value

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

Naming functions

A

One or more characters long consisting of letters, numbers, or underscore character.

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

Parts of a function

A

Function header - begins with def to :
Def = definition, Name of function, functions parameter list, then :

Documentation string

Function body
Indented block of code

Return a value - then jumps out of the function to the point in the program where it was called. Return id usually the last line of a function to be executed.

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

Function definition

A

A reusable chunk of code

Block of code with a name that takes input, provides output, can be stored.

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

What is the “scope “ of a variable or function?

A

It is where in the program a variable or function is accessible or visible.

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

Local variable

A

Any variable assigned for the first time within a function

Local variables are usable only within the function they are local to.

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

Global variables

A

Variables declared outside of any function

They are readable anywhere by any function or code within the program.

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

Main() function

A

The main() function is by convention assumed to be the starting point of your program.

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

Function parameters

A

Parameters pass data into a function

Pass by reference
When you pass parameters, the function refers to the original passed values using new names.

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

Default parameter values

A

Default values are only evaluated once, the first time they are called.

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

Keyword parameters

A

To call a function that uses keyword parameters, pass data in the form param = value.

Benefits
Make parameter values clear and easier to read

The order in which you call keyword parameters does not matter.

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

Module

A

A module is a collection of related functions and variables.

A module is a toolbox of helpful functions that you can use when writing other programs.

Usually does not have a main() function.

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

Functions

A

A named piece of code. Can take any number and type of input parameters, and return any number and t ype of output results.

Define function
Call function

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