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)
2
Q
What are the main elements of a function?
A
- Name of function
- Brackets with arguments
- Followed by :
- Indented code block
- return
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.
4
Q
If there is no return in the function, what is its value?
A
None
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'
6
Q
How do you add optional arguments with default values to a function header?
A
def greet(who="Colin"):