Functions Flashcards
What important key word is used to create new function in Python?
def foo(params):
How is called the setion that defines the function. How is it look like?
it is called the header, it holds parameters: def hello_word(name):
What is a good practice to do with every function (and all pieces of code really)
def foo(name): #to include comments """this one prints your name if you have one. lol""" print name
How is called the biggest part of every function. (hopefully it is not a comment xD)
Body - be a body - ilg
How multiline comment is called inside the function
””” DOCSTRING “””
What have you to do with function to implement it?
After defining a function, it must be called to be implemented.
Power function
def power(base, exponent): # Add your parameters here! result = base**exponent print "%d to the power of %d is %d." % (base, exponent, result)
Can function call other functions
YES. THAT IS THE BASIC OF RECURSION FOR BRIAN SAKE
What is keyword ‘import’ used for
For importing MODULES
What a ‘module’ is
A module is a file that contains definitions—including variables and functions—that you can use once it is imported.
What ‘NameError’ means
means that Python doesn’t know what used thing is -> it was not defined yet
Where sqrt() function is? In which module
import math
How to properly call sqrt() function
math.sqrt()
How to import certain variables, functions or classes form module. What is a syntax of this.
from module import function from math import sqrt # now you don't have to type math.sqrt() - it's now sqrt()
How to import all things to be in yout scope
from module import *