Week 3 Chapter 3 Functions Flashcards

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?

A

Colon :

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?

A

Yes

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
Q

What happens to local variables when a function exists

A

They are deleted

26
Q

When a global variable is accessed in a function where is it coming from?

A

From outside the function

27
Q

Functions allow local variables that are ______ and can hide ________

A

Functions allow local variables that exist only inside the function and can hide other variables that are outside the function

28
Q

When you define a variable in the global scope, where can you use it?

A

Inside and outside of functions. Local and outside

29
Q

When a variable is made in a function (local scope) can you call it in the global scope?

A

No you cannot

30
Q

How do I get info about a module

A

Use print command in Python

31
Q

In a function definition what is def and what does it do?

A

Def is a keyword that signals that this is going to be a function definition

32
Q

Once you have defined a function can you use it in another function?

A

Yes you can

33
Q

What is the flow of execution?

A

That execution begins at the first statement of a program. Then it flows from top to bottom one at a time.

34
Q

When are statements in a function executed?

A

When it is called.

35
Q

What is a parameter?

A

Name used inside a function to refer to the value passed as an argument

36
Q

Are parameters in a function also local?

A

Yes

37
Q

When you create a variable outside of a function what is the function name it belongs to?

A

main

38
Q

If an error occurs with functions what does Python do?

A

Prints name of function and name of function that called it

39
Q

In a Python error message what is the list of functions called?

A

Trace back

40
Q

What do fruitful functions do?

A

Yield a result

41
Q

What do void functions do?

A

They will display something but have the none data type even if you assign them to a variable.

42
Q

What are two ways to import modules?

A

Use import and from to import a specific object

43
Q

What happens when I do this from math import *

A

Imports everything from math module

44
Q

Advantage of importing everything from a module?

A

Code can be more concise

45
Q

Disadvantage of importing everything from a module?

A

Might be conflicts between names defined in different modules or with variable name you defined with module variable name.

46
Q

If a recursion never a reaches a base what is it called?

A

An infinite recursion but really it isn’t infinite

47
Q

In Python 2 what is input()

A

Raw_input()