Functions Flashcards

1
Q

A block of code designed to perform a specific task

A

Function

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

Every function contains two pieces - what are they called?

A

Header & body

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

What does the keyword ‘return’ tell Python?

A

We are about to exit a function

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

A header specifies what?

A

Name of function & its arguments

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

The body specifies what?

A

The work that the function does

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

Every function header begins with what?

A

def

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

For every function, the parenthesis enclosing the function argument(s) must be followed by what

A

A colon :

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

Every line of code must be indented by how many spaces?

A

Four

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

What is the final line of code called?

A

Return statement

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

Running the function is the same as saying what?

A

Calling the function

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

What is the goal when coding?

A

Write as little as possible

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

What function would you use if you forgot what something does?

A

Help()

e.g help(round)

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

When you write a function and provide a description what is that called?

A

Docstring

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

When you call help() on a function, what will it show?

A

Docstring

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

Good programmers use what?

A

Docstrings

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

What does this mean ‘\n’?

A

New line

17
Q

What does sep do?

A

It adds a separator between strings to be printed

18
Q

What does the keyword “pass” do?

A

Literally nothing. It’s a placeholder bc after we begin a code block, Python requires at least one line of code

19
Q

What does ndigits=-1 round to?

A

The nearest 10

20
Q

What does ndigit=-2 round to?

A

The nearest 100

21
Q

How can you comment & uncomment all at once?

A

Highlight then press ctrl + /

22
Q

What is the purpose of a function?

A

Allows to not have to continually write code over and over again

23
Q

What is a way to store code that should only run when your file is executed as a script

A

if __name__ == “__main__”

24
Q

This allows you to execute code when the file runs as a script, but not when it’s imported as a module

A

if __name__ == “__main__”

25
Q

What is the difference between returning and printing?

A

When you return something, you can set it equal to another variable and that way you call the results in that variable

Printing is just printing the value