Defining a function gives it a name, but does not run it. A function call runs its body with supplied values and can provide a result for the rest of the program. section 21.2
A call works like this:
- Write the function name with parentheses and actual parameters—the values used in the call. These map to formal parameters in order. section 21.2
- The call creates a scope for that invocation. Its variables are local to the call and disappear when it returns. section 21.2
- The call expression is replaced by the returned value. A function can return one tuple containing multiple values; without an explicit return, it returns None. section 21.4
Listing 21.3. How to make a call to a function
def word_length(word1, word2): #1
word = word1+word2 #1
return len(word) #1
print("this never gets printed")
length1 = word_length("Rob", "Banks") #2
length2 = word_length("Barbie", "Kenn") #2
length3 = word_length("Holly", "Jolley") #2
print("One name is", length1, "letters long.") #3
print("Another name is", length2, "letters long.") #3
print("The final name is", length3, "letters long.") #3
Follow calls to word_length with different names, then see how each returned length is used. section 21.2






