Multiple Parameters

In [5]:
def happy():
    print("Happy birthday to you!")
In [6]:
def sing(first, middle, last):
    # Person should be a string for somebody's name
    happy()
    happy()
    # Using standard string formatting techniques
    #print("Happy birthday, dear {0} {1} {2}…".format(first, middle, last))
    
    # Uses interpolated strings in Python 3.6 or later
    print(f"Happy birthday, dear {first} {middle} {last}…")
    happy()
In [7]:
sing("Fred")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-f79489d67c52> in <module>()
----> 1 sing("Fred")

TypeError: sing() missing 2 required positional arguments: 'middle' and 'last'
In [8]:
sing("Philip", "J", "Fry")
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Philip J Fry…
Happy birthday to you!
In [9]:
sing("James", "Tiberius", "Kirk")
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear James Tiberius Kirk…
Happy birthday to you!
In [10]:
sing("Sheldon", "Cooper")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-fd1dd0f4a10a> in <module>()
----> 1 sing("Sheldon", "Cooper")

TypeError: sing() missing 1 required positional argument: 'last'
In [13]:
sing("Sheldon", "", "Cooper")
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Sheldon  Cooper…
Happy birthday to you!

Positional Parameters

In [14]:
sing("James", "Tiberius", "Kirk")  # Positionally first, middle, and last
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear James Tiberius Kirk…
Happy birthday to you!
In [15]:
sing("Kirk", "James", "Tiberius")  # Positionally first, middle, and last
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Kirk James Tiberius…
Happy birthday to you!