Topic 4 Flashcards

1
Q

How would you write a custom function, that when called, would print the word ‘‘hello”?

A
def hello()
   print("Hello")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would you use a function in python?

A

It is used to group code that is used multiple times when called.

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

See the following code example.

def hello(name)

What is the proper term for “name” in context when using functions.

A

It is called a parameter.

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

When you call a function and pass a value into the function, what is the passed value called?

A

An argument.

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

Variables that exist inside of a function have what type of scope?

A

Local scope

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

Variables that exist outside of all functions have what type of scope?

A

Global scope

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

Can a variable be local and global scope?

A

No

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

If an assignment variable is assigned within a function, what scope does that variable have?

Example:

def spam():
   eggs = 10
   print(eggs)
A

A assignment statement within a function has local scope.

No assignment statement means it has global scope.

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