Frameworks 005 Flashcards
What is a function?
A Function is a piece of code that you can reuse by calling its name.
What is a benefit in the end of using functions whenever you can?
It allows us to make less mistakes when writing code as we do not need to rewrite more code.
What is this an example of?:
def hello():
print(“Hello User”)
hello()
A function.
What will this print?:
def ten_squared():
return 10**2
x = ten_squared()
print(x)
100
What will this print?:
def sum(num1, num2):
return num1+num2
x = sum(5, 10)
print(x)
15
How many things should a function do?
1 or 2 at the most as it could be easy to get the wrong value and is harder to debug if longer than 1 to 2.
What are args?
They are when you input multiple arguments into a function.
What are kwargs?
They are when you specify different variables to be inputted into a function.