Week 6: Functions Flashcards

(13 cards)

1
Q

Functions

A

Functions are used to groups of predefined statements for repeated operations. Used to reduce redundancy and keep your program small and clear.

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

Function Definition

A

This is made of the function’s name and a block of statements.

e.g. def calc_pizza_area():

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

Function call

A

You can use the functions name to “call” it, which causes the function statements to run.

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

Return Statement

A

A function can return one value by using a return statement.

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

Parameters

A

Is a named variable listed inside the parentheses in the function’s definition. It acts as a place holder or local variable that is used within the body of the function to show what kind of data the function will use.

e.g. def add(x, y):

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

Arguments

A

The argument is the actual value that is given to the function when it is called. These values are assigned to the corresponding parameters at runtime.

e.g. def add(5, 3):

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

Polymorphism

A

This happens when your function adds different types together.

e.g. (“x” * 5 = xxxxx)

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

function stubs

A

You write functions incrementally by writing out all the functions you think you may need and then using the “pass” keyword that acts as a placeholder until you are ready to work on it.

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

Local Variables

A

Are variables that are defined INSIDE the function and are invisible to the code outside the function.

use LIBERALLY

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

Global Variables

A

These are variables that are defined OUTSIDE the function and can be used both inside and outside of the function.

use SPARINGLY

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

Scope

A

Scope refers to the area of code where a name is visible.
- Built-in scope = all built in names int(), str() ect.

  • global scope.
  • local scope.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

docstring

A

This is a way of documenting each function so that people can understand your code.

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

help()

A

The help() function will print out the docstring for whatever function you are trying to use so you can get more information on how to call it.

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