2. Funtions and getting help Flashcards

1
Q

What’s the best way of getting help in Python e.g. for the round function?

A

help(round)

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

What are the main elements of a function?

A
  • Name of function
  • Brackets with arguments
  • Followed by :
  • Indented code block
  • return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you write a docstring?

A

The docstring is a triple-quoted string (which may span multiple lines) that comes immediately after the header of a function.

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

If there is no return in the function, what is its value?

A

None

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

How do you start a new line between each of the arguments in the print function?

A

Define the optinoal argument:
sep='\n'

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

How do you add optional arguments with default values to a function header?

A

def greet(who="Colin"):

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