Python function keyword arg code example
Example 1: Python function keyword arg
def greet(*names):
"""This function greets all
the person in the names tuple."""
for name in names:
print("Hello", name)
greet("Monica", "Luke", "Steve", "John")
Example 2: Python function keyword arg
def greet(name, msg="Good morning!"):
"""
This function greets to
the person with the
provided message.
If the message is not provided,
it defaults to "Good
morning!"
"""
print("Hello", name + ', ' + msg)
greet("Kate")
greet("Bruce", "How do you do?")Copied
Example 3: Python function keyword arg
greet(name = "Bruce",msg = "How do you do?")
greet(msg = "How do you do?",name = "Bruce")
1 positional, 1 keyword argument
greet("Bruce", msg = "How do you do?")