Functions Flashcards
Function to convert a letter to its underlying ASCII
ord(“a”)
Function to convert an integer to its corresponding ASCII
chr(7)
Common functions
len()
str()
print ()
int ()
Parameters and arguments
Parameters are a piece of input that the function expects, while arguments are the actual pieces of input a specific function call receives.
So, a ‘multiply’ function would potentially expect two numbers: those are the parameters. If I call ‘multiply’ with the two numbers 7 and 2 are arguments. It would then return the output, 14.
def currencyAmount(currency, amount)
….
….
print(currencyAmount(“GBP”,5)
Parameters: currency, amount
Arguments: “GBP”, 5
What finish the function execution?
return value
Return None
If a function doesn’t otherwise return anything, it return None
Keyword parameters sep end
print(“A”, “B”, “C”, sep = “”, end = “”)
print(“D”, “E”, “F”, sep = “”, end = “”)
ABCDEF
Keyword parameters 2
print(“A”, “B”, “C”, sep = “#”, end = “?”)
print (“D”, “E”, “F”, sep = “%”, end = “!”)
A#B#C#?D%E%F!