Week 3 Chapter 3 Functions Flashcards

(47 cards)

1
Q

What happens when you define a function?

A

Specifying the name and the sequence of statements

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

When a function is called what is the value in parentheses usually called?

A

Usually called the argument

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

What is the official name for a result of a function?

A

Return value

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

When int converts floating-point values to integers, what does it do?

A

It take the fraction part away and returns value like that

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

What would 3.9 look like when converted to integer?

A

3

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

What data types can float convert?

A

Strings and floating point numbers

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

What is a module?

A

File that contains a collection of related functions

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

Before we can use a module what do we have to do?

A

Have to import said module

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

What does dot notation format look like?

A

Math.log(23)

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

What is one of the most useful things about programming?

A

Ability to take small building blocks and compose them.

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

Where can you not put a arbitrary expression?

A

On the left side of an assignment value

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

The left side of an assignment statement has to have what?

A

A variable name

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

What does a function definition do?

A

It specifies the name of a new function and the sequence of statements that execute when the function is called.

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

What are the rules for function names?

A

Can’t have keywords, illegal characters, and the start has to be a letter not a number.

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

What should you avoid with function names?

A

Having a variable and a function with the same name

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

What do empty parentheses after a function name indicate?

A

That it doesn’t take any arguments

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

What is the first line of a function definition called?

A

A header

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

What is the other part of a function definition called (besides header)?

A

The body

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

The header has to end with what, in a function definition?

20
Q

Does the body in a function definition have to be indented?

How many spaces if in indented?

A

Yes it does, with 4 spaces in each line

21
Q

What is a function?

A

Named sequence of statements that perform a computation

22
Q

Can functions be used to repeat tasks that don’t return values?

23
Q

When is a return optional in a function?

A

When the function doesn’t need to send back a value.

24
Q

When a function is done running what happens to the local variables in the function?

A

They cease to exist

25
What happens to local variables when a function exists
They are deleted
26
When a global variable is accessed in a function where is it coming from?
From outside the function
27
Functions allow local variables that are ______ and can hide ________
Functions allow local variables that exist only inside the function and can hide other variables that are outside the function
28
When you define a variable in the global scope, where can you use it?
Inside and outside of functions. Local and outside
29
When a variable is made in a function (local scope) can you call it in the global scope?
No you cannot
30
How do I get info about a module
Use print command in Python
31
In a function definition what is def and what does it do?
Def is a keyword that signals that this is going to be a function definition
32
Once you have defined a function can you use it in another function?
Yes you can
33
What is the flow of execution?
That execution begins at the first statement of a program. Then it flows from top to bottom one at a time.
34
When are statements in a function executed?
When it is called.
35
What is a parameter?
Name used inside a function to refer to the value passed as an argument
36
Are parameters in a function also local?
Yes
37
When you create a variable outside of a function what is the function name it belongs to?
_main_
38
If an error occurs with functions what does Python do?
Prints name of function and name of function that called it
39
In a Python error message what is the list of functions called?
Trace back
40
What do fruitful functions do?
Yield a result
41
What do void functions do?
They will display something but have the none data type even if you assign them to a variable.
42
What are two ways to import modules?
Use import and from to import a specific object
43
What happens when I do this from math import *
Imports everything from math module
44
Advantage of importing everything from a module?
Code can be more concise
45
Disadvantage of importing everything from a module?
Might be conflicts between names defined in different modules or with variable name you defined with module variable name.
46
If a recursion never a reaches a base what is it called?
An infinite recursion but really it isn't infinite
47
In Python 2 what is input()
Raw_input()