FUNCTIONS Flashcards
How to define a function?
def hello(): print('Howdy!') print('Howdy!!!') print('Hello there.')
What does Define a function mean?
creating a function
What does calling a function mean?
Using function
what does passing a value mean?
giving a value to the function while calling it
What is an argument in a function?
a value being passed to the function is an argument
What is parameters?
Variables that have arguments assigned to them are parameters.
What is return value of a function?
it. In general, the value that a function call evaluates to is called the return value of the function.
What is return statement?
When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following:
The return keyword
The value or expression that the function should return
An example of a fortune teller program?
import random
def getAnswer(answerNumber): if answerNumber == 1: return "It is certain" elif answerNumber == 2: return "It is decidedly so" elif answerNumber == 3: return "Yes"
r = random.randint(1,3)
fortune = getAnswer(r)
print(fortune)
What is None value?
which represents the absence of a value
What are keyword arguments?
Keyword arguments are often used for optional parameters.
What are print() keyword arguments?
print(‘the’,’cat’,’is’, sep =’ ,’,end =’ ‘ )
what is the Call Stack by an example?
def a(): print('a() starts') ➊ b() ➋ d() print('a() returns')
def b(): print('b() starts') ➌ c() print('b() returns')
def c(): ➍ print('c() starts') print('c() returns')
def d(): print('d() starts') print('d() returns')
➎ a()
Parameters and variables that are assigned in a called function are said to exist in that function’s……..
local scope
Variables that are assigned outside all functions are said to exist in the ………..
global scope