100 Days of Code - Functions with Outputs (Day10)

Functions with Outputs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def ex_function() :
result = 'function result'
return result

output = ex_function()

# ex1

def format_name(f_name, l_name):
formated_f_name = f_name.title()
formated_l_name = l_name.title()
return f"{formated_f_name} {formated_l_name}"

formated_string = format_name('Clayton', 'Shih')

# ex2
def add(num1, num2):
return num1 + num2
operations = {
"+" : add
}

calculation_function = operations[operation_symbol]
calculation_function(1,2)

Doctrings

Docstrings are basically a way for us to create little bits of documentation as
we’re coding along in our functions or in our other blocks of code.

1
2
3
4
def ex_function() :
""" Docstring example """ # 一定要寫在第一行,在用這function時會看到 Docstring 的提示
result = 'function result'
return resule