-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_functions.py
More file actions
55 lines (40 loc) · 1.5 KB
/
hello_functions.py
File metadata and controls
55 lines (40 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def say_hello(name):
"""
Print the hello greeting to the console.
:param name: The name of the person to say hello to
:return: None
"""
print("Hello " + name)
def default_argument_literal(initial_string, default="default value!"):
"""
Print whatever the user inputs, plus a default value, unless it's overridden.
:param initial_string: Initial string
:param default: A default hard-coded string, which can be overridden
:return: None
"""
print(initial_string, default)
def variable_args_tuple_mapping(*args):
"""
Print out a list of given positional arguments.
:param args: A set of positional parameters, which will be mapped to a tuple within the function
:return: None
"""
for arg in args:
print(arg)
def variable_args_dict_mapping(**args):
"""
Print out the given keyword arguments.
:param args: A set of keyword parameters, which will be mapped to a dictionary type within the function
:return: None
"""
for arg in args:
print(arg, ":", args[arg])
if __name__ == "__main__":
"""
Demonstrate how to call various functions.
"""
say_hello("The Knights Who Say Ni")
default_argument_literal("Oh look, a flying...")
default_argument_literal("Oh look, a flying...", "circus!")
variable_args_tuple_mapping("positional parameter 1", "positional parameter 2")
variable_args_dict_mapping(starter="spam", main="more spam", dessert="spam flavoured ice-cream", drink="spam juice")