Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views11 pages

Day-06 More Functions

The document discusses advanced concepts in Python functions, including default argument values, positional and keyword arguments, and how to accept an arbitrary number of arguments. It provides examples of functions that print personalized messages and describes how to handle various types of arguments effectively. Additionally, it includes exercises for practicing these concepts with different scenarios.

Uploaded by

hatim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

Day-06 More Functions

The document discusses advanced concepts in Python functions, including default argument values, positional and keyword arguments, and how to accept an arbitrary number of arguments. It provides examples of functions that print personalized messages and describes how to handle various types of arguments effectively. Additionally, it includes exercises for practicing these concepts with different scenarios.

Uploaded by

hatim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [1]: def thank_you(name):


# This function prints a two-line personalized thank you message.
print("\nYou are doing good work, %s!" % name)
print("Thank you very much for your efforts on this project.")
Day-06
thank_you('Adriana')
thank_you('Billy')
More Functions thank_you('Caroline')

You are doing good work, Adriana!


Thank you very much for your efforts on this project.
Earlier we learned the most bare-boned versions of functions. In this section we will learn more general concepts
about functions, such as how to use functions to return values, and how to pass different kinds of data structures You are doing good work, Billy!
between functions. Thank you very much for your efforts on this project.

You are doing good work, Caroline!


Thank you very much for your efforts on this project.
Contents
Default argument values This function works fine, but it fails if you don't pass in a value:
Exercises
Positional arguments In [1]: def thank_you(name):
Exercises # This function prints a two-line personalized thank you message.
Keyword arguments print("\nYou are doing good work, %s!" % name)
print("Thank you very much for your efforts on this project.")
Mixing positional and keyword arguments
Exercises thank_you('Billy')
Accepting an arbitrary number of arguments thank_you('Caroline')
Accepting a sequence of arbitrary length thank_you()
Accepting an arbitrary number of keyword arguments
You are doing good work, Billy!
Thank you very much for your efforts on this project.

You are doing good work, Caroline!


Default argument values Thank you very much for your efforts on this project.

---------------------------------------------------------------------------
When we first introduced functions, we started with this example: TypeError Traceback (most recent call last)
<ipython-input-1-8d6428a8085c> in <module>()
6 thank_you('Billy')
7 thank_you('Caroline')
----> 8 thank_you()

TypeError: thank_you() missing 1 required positional argument: 'name'

That makes sense; the function needs to have a name in order to do its work, so without a name it is stuck.

If you want your function to do something by default, even if no information is passed to it, you can do so by
giving your arguments default values. You do this by specifying the default values when you define the function:

file:///C:/Users/Administrator/Downloads/07 More Functions.html 1/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 2/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [2]: def thank_you(name='everyone'): In [ ]: # Ex 8.2 : Favorite Movie


# This function prints a two-line personalized thank you message.
# If no name is passed in, it prints a general thank you message # put your code here
# to everyone.
print("\nYou are doing good work, %s!" % name)
print("Thank you very much for your efforts on this project.")
top
thank_you('Billy')
thank_you('Caroline')
thank_you()
Positional Arguments
You are doing good work, Billy!
Thank you very much for your efforts on this project.
Much of what you will have to learn about using functions involves how to pass values from your calling
You are doing good work, Caroline! statement to the function itself. The example we just looked at is pretty simple, in that the function only needed
Thank you very much for your efforts on this project.
one argument in order to do its work. Let's take a look at a function that requires two arguments to do its work.
You are doing good work, everyone!
Let's make a simple function that takes in three arguments. Let's make a function that takes in a person's first
Thank you very much for your efforts on this project.
and last name, and then prints out everything it knows about the person.

This is particularly useful when you have a number of arguments in your function, and some of those arguments
Here is a simple implementation of this function:
almost always have the same value. This allows people who use the function to only specify the values that are
unique to their use of the function.
In [22]: def describe_person(first_name, last_name, age):
# This function takes in a person's first and last name,
# and their age.
top
# It then prints this information out in a simple format.
print("First name: %s" % first_name.title())
print("Last name: %s" % last_name.title())
print("Age: %d\n" % age)
Exercises
describe_person('brian', 'kernighan', 71)
describe_person('ken', 'thompson', 70)
Games
describe_person('adele', 'goldberg', 68)
Write a function that accepts the name of a game and prints a statement such as, "I like playing chess!"
First name: Brian
Give the argument a default value, such as chess . Last name: Kernighan
Call your function at least three times. Make sure at least one of the calls includes an argument, and at least Age: 71
one call includes no arguments.
First name: Ken
Last name: Thompson
Favorite Movie Age: 70
Write a function that accepts the name of a movie, and prints a statement such as, "My favorite movie is The
First name: Adele
Princess Bride." Last name: Goldberg
Give the argument a default value, such as The Princess Bride . Age: 68
Call your function at least three times. Make sure at least one of the calls includes an argument, and at least
one call includes no arguments.

In [ ]: # Ex 8.1 : Games

# put your code here

file:///C:/Users/Administrator/Downloads/07 More Functions.html 3/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 4/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

The arguments in this function are first_name , last_name , and age . These are called positional top
arguments because Python knows which value to assign to each by the order in which you give the function
values. In the calling line

describe_person('brian', 'kernighan', 71) Exercises

Favorite Colors
we send the values brian, kernighan, and 71 to the function. Python matches the first value brian with the first
argument first_name . It matches the second value kernighan with the second argument last_name . Finally Write a function that takes two arguments, a person's name and their favorite color. The function should print
it matches the third value 71 with the third argument age . out a statement such as "Hillary's favorite color is blue."
Call your function three times, with a different person and color each time.
This is pretty straightforward, but it means we have to make sure to get the arguments in the right order.

Phones

Write a function that takes two arguments, a brand of phone and a model name. The function should print
If we mess up the order, we get nonsense results or an error: out a phrase such as "iPhone 6 Plus".
Call your function three times, with a different combination of brand and model each time.
In [23]: def describe_person(first_name, last_name, age):
# This function takes in a person's first and last name,
# and their age. In [1]: # Ex 8.3 : Favorite Colors
# It then prints this information out in a simple format.
print("First name: %s" % first_name.title()) # put your code here
print("Last name: %s" % last_name.title())
print("Age: %d\n" % age) In [ ]: # Ex 8.4 : Phones

describe_person(71, 'brian', 'kernighan') # put your code here


describe_person(70, 'ken', 'thompson')
describe_person(68, 'adele', 'goldberg')

--------------------------------------------------------------------------- top
AttributeError Traceback (most recent call last)
<ipython-input-23-59fb6d0341c1> in <module>()
7 print("Age: %d\n" % age)
8
----> 9 describe_person(71, 'brian', 'kernighan')
Keyword arguments
10 describe_person(70, 'ken', 'thompson') Python allows us to use a syntax called keyword arguments. In this case, we can give the arguments in any
11 describe_person(68, 'adele', 'goldberg')
order when we call the function, as long as we use the name of the arguments in our calling statement. Here is
<ipython-input-23-59fb6d0341c1> in describe_person(first_name, last_name, ag how the previous code can be made to work using keyword arguments:
e)
3 # and their age.
4 # It then prints this information out in a simple format.
----> 5 print("First name: %s" % first_name.title())
6 print("Last name: %s" % last_name.title())
7 print("Age: %d\n" % age)

AttributeError: 'int' object has no attribute 'title'

This fails because Python tries to match the value 71 with the argument first_name , the value brian with the
argument last_name , and the value kernighan with the argument age . Then when it tries to print the value
first_name.title() , it realizes it can't use the title() method on an integer.

file:///C:/Users/Administrator/Downloads/07 More Functions.html 5/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 6/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [3]: def describe_person(first_name, last_name, age): In [25]: def describe_person(first_name, last_name, age, favorite_language):
# This function takes in a person's first and last name, # This function takes in a person's first and last name,
# and their age. # their age, and their favorite language.
# It then prints this information out in a simple format. # It then prints this information out in a simple format.
print("First name: %s" % first_name.title()) print("First name: %s" % first_name.title())
print("Last name: %s" % last_name.title()) print("Last name: %s" % last_name.title())
print("Age: %d\n" % age) print("Age: %d" % age)
print("Favorite language: %s\n" % favorite_language)
describe_person(age=71, first_name='brian', last_name='kernighan')
describe_person(age=70, first_name='ken', last_name='thompson') describe_person('brian', 'kernighan', 71, 'C')
describe_person(age=68, first_name='adele', last_name='goldberg') describe_person('ken', 'thompson', 70, 'Go')
describe_person('adele', 'goldberg', 68, 'Smalltalk')
First name: Brian
Last name: Kernighan First name: Brian
Age: 71 Last name: Kernighan
Age: 71
First name: Ken Favorite language: C
Last name: Thompson
Age: 70 First name: Ken
Last name: Thompson
First name: Adele Age: 70
Last name: Goldberg Favorite language: Go
Age: 68
First name: Adele
Last name: Goldberg
Age: 68
This works, because Python does not have to match values to arguments by position. It matches the value 71 Favorite language: Smalltalk
with the argument age , because the value 71 is clearly marked to go with that argument. This syntax is a little
more typing, but it makes for very readable code.
We can expect anyone who uses this function to supply a first name and a last name, in that order. But now we
are starting to include some information that might not apply to everyone. We can address this by keeping
positional arguments for the first name and last name, but expect keyword arguments for everything else. We
Mixing positional and keyword arguments
can show this works by adding a few more people, and having different information about each person:
It can make good sense sometimes to mix positional and keyword arguments. In our previous example, we can
expect this function to always take in a first name and a last name. Before we start mixing positional and
keyword arguments, let's add another piece of information to our description of a person. Let's also go back to
using just positional arguments for a moment:

file:///C:/Users/Administrator/Downloads/07 More Functions.html 7/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 8/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [6]: def describe_person(first_name, last_name, age=None, favorite_language=None, d


ied=None): top
"""
This function takes in a person's first and last name, their age,
and their favorite language.
It then prints this information out in a simple format. Exercises
"""

print("First name: %s" % first_name.title()) Sports Teams


print("Last name: %s" % last_name.title())
Write a function that takes in two arguments, the name of a city and the name of a sports team from that city.
# Optional information: Call your function three times, using a mix of positional and keyword arguments.
if age:
print("Age: %d" % age)
World Languages
if favorite_language:
print("Favorite language: %s" % favorite_language) Write a function that takes in two arguments, the name of a country and a major language spoken there.
if died:
Call your function three times, using a mix of positional and keyword arguments.
print("Died: %d" % died)
# Blank line at end.
print("\n")
In [ ]: # Ex 8.5 : Sports Team
describe_person('brian', 'kernighan', favorite_language='C')
describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk') # put your code here
describe_person('dennis', 'ritchie', favorite_language='C', died=2011)
describe_person('guido', 'van rossum', favorite_language='Python') In [ ]: # Ex 8.6 : Word Languages

# put your code here


First name: Brian
Last name: Kernighan
Favorite language: C
top

First name: Adele


Last name: Goldberg
Age: 68
Favorite language: Smalltalk Accepting an arbitrary number of arguments
We have now seen that using keyword arguments can allow for much more flexible calling statements.
First name: Dennis
This benefits you in your own programs, because you can write one function that can handle many different
Last name: Ritchie
Favorite language: C situations you might encounter.
Died: 2011 This benefits you if other programmers use your programs, because your functions can apply to a wide
range of situations.
This benefits you when you use other programmers' functions, because their functions can apply to many
First name: Guido
situations you will care about.
Last name: Van Rossum
Favorite language: Python
There is another issue that we can address, though. Let's consider a function that takes two number in, and
prints out the sum of the two numbers:

Everyone needs a first and last name, but everthing else is optional. This code takes advantage of the Python
keyword None , which acts as an empty value for a variable. This way, the user is free to supply any of the
'extra' values they care to. Any arguments that don't receive a value are not displayed. Python matches these
extra values by name, rather than by position. This is a very common and useful way to define functions.

file:///C:/Users/Administrator/Downloads/07 More Functions.html 9/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 10/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [39]: def adder(num_1, num_2): In [31]: def example_function(arg_1, arg_2, *arg_3):


# This function adds two numbers together, and prints the sum. # Let's look at the argument values.
sum = num_1 + num_2 print('\narg_1:', arg_1)
print("The sum of your numbers is %d." % sum) print('arg_2:', arg_2)
print('arg_3:', arg_3)
# Let's add some numbers.
adder(1, 2) example_function(1, 2)
adder(-1, 2) example_function(1, 2, 3)
adder(1, -2) example_function(1, 2, 3, 4)
example_function(1, 2, 3, 4, 5)
The sum of your numbers is 3.
The sum of your numbers is 1. arg_1: 1
The sum of your numbers is -1. arg_2: 2
arg_3: ()

This function appears to work well. But what if we pass it three numbers, which is a perfectly reasonable thing to arg_1: 1
arg_2: 2
do mathematically?
arg_3: (3,)

In [40]: def adder(num_1, num_2): arg_1: 1


# This function adds two numbers together, and prints the sum. arg_2: 2
sum = num_1 + num_2 arg_3: (3, 4)
print("The sum of your numbers is %d." % sum)
arg_1: 1
# Let's add some numbers. arg_2: 2
adder(1, 2, 3) arg_3: (3, 4, 5)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last) You can use a for loop to process these other arguments:
<ipython-input-40-9939998d2a01> in <module>()
5
6 # Let's add some numbers.
----> 7 adder(1, 2, 3)

TypeError: adder() takes exactly 2 arguments (3 given)

This function fails, because no matter what mix of positional and keyword arguments we use, the function is only
written two accept two arguments. In fact, a function written in this way will only work with exactly two arguments.

Accepting a sequence of arbitrary length


Python gives us a syntax for letting a function accept an arbitrary number of arguments. If we place an argument
at the end of the list of arguments, with an asterisk in front of it, that argument will collect any remaining values
from the calling statement into a tuple. Here is an example demonstrating how this works:

file:///C:/Users/Administrator/Downloads/07 More Functions.html 11/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 12/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [30]: def example_function(arg_1, arg_2, *arg_3): In [8]: def adder(*nums):


# Let's look at the argument values. """This function adds the given numbers together and prints the sum."""
print('\narg_1:', arg_1) # Print the results.
print('arg_2:', arg_2) print("The sum of your numbers is %d." % sum(nums))
for value in arg_3:
print('arg_3 value:', value) # Let's add some numbers.
adder(1, 2, 3)
example_function(1, 2)
example_function(1, 2, 3) The sum of your numbers is 6.
example_function(1, 2, 3, 4)
example_function(1, 2, 3, 4, 5)
In this new version, Python does the following:
arg_1: 1
arg_2: 2 stores the first value in the calling statement in the argument num_1 ;
stores the second value in the calling statement in the argument num_2 ;
arg_1: 1
arg_2: 2 stores all other values in the calling statement as a tuple in the argument nums .
arg_3 value: 3

arg_1: 1
arg_2: 2 We can then "unpack" these values, using a for loop. We can demonstrate how flexible this function is by calling
arg_3 value: 3 it a number of times, with a different number of arguments each time.
arg_3 value: 4
In [28]: def adder(num_1, num_2, *nums):
arg_1: 1
# This function adds the given numbers together,
arg_2: 2
# and prints the sum.
arg_3 value: 3
arg_3 value: 4
# Start by adding the first two numbers, which
arg_3 value: 5
# will always be present.
sum = num_1 + num_2

We can now rewrite the adder() function to accept two or more arguments, and print the sum of those numbers: # Then add any other numbers that were sent.
for num in nums:
In [7]: def adder(*nums): sum = sum + num
"""This function adds the given numbers together and prints the sum."""
# Print the results.
s = 0 print("The sum of your numbers is %d." % sum)
for num in nums:
s = s + num
# Print the results. # Let's add some numbers.
print("The sum of your numbers is %d." % s) adder(1, 2)
adder(1, 2, 3)
# Let's add some numbers. adder(1, 2, 3, 4)
adder(1, 2, 3) adder(1, 2, 3, 4, 5)

The sum of your numbers is 6. The sum of your numbers is 3.


The sum of your numbers is 6.
The sum of your numbers is 10.
The sum of your numbers is 15.

top

file:///C:/Users/Administrator/Downloads/07 More Functions.html 13/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 14/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

The third argument has two asterisks in front of it, which tells Python to collect all remaining key-value arguments
Accepting an arbitrary number of keyword arguments in the calling statement. This argument is commonly named kwargs. We see in the output that these key-values
are stored in a dictionary. We can loop through this dictionary to work with all of the values that are passed into
Python also provides a syntax for accepting an arbitrary number of keyword arguments. The syntax looks like
the function:
this:

In [9]: import sys


In [36]: def example_function(arg_1, arg_2, **kwargs):
f = open('./test.txt', 'w') # Let's look at the argument values.
print('\narg_1:', arg_1)
FILE_OUT = f #sys.stdout print('arg_2:', arg_2)
for key, value in kwargs.items():
def example_function(*args, **kwargs): print('arg_3 value:', value)
print(*args, sep='++', end=' ', file=FILE_OUT)
for k, v in kwargs.items(): example_function('a', 'b')
print(k, ': ', v, end=' ', file=FILE_OUT) example_function('a', 'b', value_3='c')
example_function('a', 'b', value_3='c', value_4='d')
example_function(1, 2, 4, 5) example_function('a', 'b', value_3='c', value_4='d', value_5='e')
example_function(1, 3, value=1, name=5)
example_function(store='ff', quote='Do. Or do not. There is no try.') arg_1: a
arg_2: b
f.close()
arg_1: a
In [34]: def example_function(arg_1, arg_2, **kwargs): arg_2: b
# Let's look at the argument values. arg_3 value: c
print('\narg_1:', arg_1)
print('arg_2:', arg_2) arg_1: a
print('arg_3:', kwargs) arg_2: b
arg_3 value: d
example_function('a', 'b') arg_3 value: c
example_function('a', 'b', value_3='c')
example_function('a', 'b', value_3='c', value_4='d') arg_1: a
example_function('a', 'b', value_3='c', value_4='d', value_5='e') arg_2: b
arg_3 value: e
arg_1: a arg_3 value: d
arg_2: b arg_3 value: c
arg_3: {}

arg_1: a
arg_2: b
arg_3: {'value_3': 'c'}

arg_1: a
arg_2: b
arg_3: {'value_4': 'd', 'value_3': 'c'}

arg_1: a
arg_2: b
arg_3: {'value_5': 'e', 'value_4': 'd', 'value_3': 'c'}

file:///C:/Users/Administrator/Downloads/07 More Functions.html 15/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 16/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [9]: def example_function(**kwargs): In [1]: def describe_person(first_name, last_name, age=None, favorite_language=None, d


print(type(kwargs)) ied=None):
for key, value in kwargs.items(): # This function takes in a person's first and last name,
print('{}:{}'.format(key, value)) # their age, and their favorite language.
# It then prints this information out in a simple format.
example_function(first=1, second=2, third=3)
example_function(first=1, second=2, third=3, fourth=4) # Required information:
example_function(name='Valerio', surname='Maggio') print("First name: %s" % first_name.title())
print("Last name: %s" % last_name.title())
<class 'dict'>
second:2 # Optional information:
third:3 if age:
first:1 print("Age: %d" % age)
<class 'dict'> if favorite_language:
second:2 print("Favorite language: %s" % favorite_language)
fourth:4 if died:
third:3 print("Died: %d" % died)
first:1
<class 'dict'> # Blank line at end.
name:Valerio print("\n")
surname:Maggio
describe_person('brian', 'kernighan', favorite_language='C')
describe_person('ken', 'thompson', age=70)
Earlier we created a function that let us describe a person, and we had three things we could describe about a describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk')
person. We could include their age, their favorite language, and the date they passed away. But that was the describe_person('dennis', 'ritchie', favorite_language='C', died=2011)
describe_person('guido', 'van rossum', favorite_language='Python')
only information we could include, because it was the only information that the function was prepared to handle:
First name: Brian
Last name: Kernighan
Favorite language: C

First name: Ken


Last name: Thompson
Age: 70

First name: Adele


Last name: Goldberg
Age: 68
Favorite language: Smalltalk

First name: Dennis


Last name: Ritchie
Favorite language: C
Died: 2011

First name: Guido


Last name: Van Rossum
Favorite language: Python

file:///C:/Users/Administrator/Downloads/07 More Functions.html 17/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 18/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

We can make this function much more flexible by accepting any number of keyword arguments. Here is what the This is pretty neat. We get the same output, and we don't have to include a bunch of if tests to see what kind of
function looks like, using the syntax for accepting as many keyword arguments as the caller wants to provide: information was passed into the function. We always require a first name and a last name, but beyond that the
caller is free to provide any keyword-value pair to describe a person. Let's show that any kind of information can
be provided to this function. We also clean up the output by replacing any underscores in the keys with a space.
In [4]: def describe_person(first_name, last_name, **kwargs):
# This function takes in a person's first and last name,
# and then an arbitrary number of keyword arguments.

# Required information:
print("First name: %s" % first_name.title())
print("Last name: %s" % last_name.title())

# Optional information:
for key in kwargs:
print("%s: %s" % (key.title(), kwargs[key]))

# Blank line at end.


print("\n")

describe_person('brian', 'kernighan', favorite_language='C')


describe_person('ken', 'thompson', age=70)
describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk')
describe_person('dennis', 'ritchie', favorite_language='C', died=2011)
describe_person('guido', 'van rossum', favorite_language='Python')

First name: Brian


Last name: Kernighan
Favorite_Language: C

First name: Ken


Last name: Thompson
Age: 70

First name: Adele


Last name: Goldberg
Age: 68
Favorite_Language: Smalltalk

First name: Dennis


Last name: Ritchie
Favorite_Language: C
Died: 2011

First name: Guido


Last name: Van Rossum
Favorite_Language: Python

file:///C:/Users/Administrator/Downloads/07 More Functions.html 19/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 20/22


1/7/22, 3:50 PM 07 More Functions 1/7/22, 3:50 PM 07 More Functions

In [6]: def describe_person(first_name, last_name, **kwargs):


# This function takes in a person's first and last name, There is plenty more to learn about using functions, but with all of this flexibility in terms of how to accept
# and then an arbitrary number of keyword arguments. arguments for your functions you should be able to write simple, clean functions that do exactly what you need
them to do.
# Required information:
print("First name: %s" % first_name.title())
print("Last name: %s" % last_name.title())
top
# Optional information:
for key in kwargs:
print("%s: %s" % (key.title().replace('_', ' '), kwargs[key]))

# Blank line at end.


print("\n")

describe_person('brian', 'kernighan', favorite_language='C', famous_book='The


C Programming Language')
describe_person('ken', 'thompson', age=70, alma_mater='UC Berkeley')
describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk')
describe_person('dennis', 'ritchie', favorite_language='C', died=2011, famous_
book='The C Programming Language')
describe_person('guido', 'van rossum', favorite_language='Python', company='Dr
opbox')

First name: Brian


Last name: Kernighan
Famous Book: The C Programming Language
Favorite Language: C

First name: Ken


Last name: Thompson
Alma Mater: UC Berkeley
Age: 70

First name: Adele


Last name: Goldberg
Age: 68
Favorite Language: Smalltalk

First name: Dennis


Last name: Ritchie
Famous Book: The C Programming Language
Favorite Language: C
Died: 2011

First name: Guido


Last name: Van Rossum
Company: Dropbox
Favorite Language: Python

file:///C:/Users/Administrator/Downloads/07 More Functions.html 21/22 file:///C:/Users/Administrator/Downloads/07 More Functions.html 22/22

You might also like