Skip to content

Commit 600785f

Browse files
committed
final code ref params in python
1 parent 0db5696 commit 600785f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

code/ch_09_tuples/_03_methods_with_ref_params.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
def main():
55
args = list()
66
out_params_bad(7, args)
7-
print("Return values (bad): {} & {:.2f}".format(args[0], args[1]))
7+
print("Return values (bad): {} & {:.2f}".format(args[0], args[1]))
88

99
# can we do better?
10+
v1, v2 = out_params(7)
11+
print("Return values (good): {} & {:.2f}".format(v1, v2))
1012

1113

14+
# pythonic!
15+
def out_params(base: float):
16+
r1 = base * base
17+
r2 = math.sqrt(base * base * base)
18+
19+
return r1, r2
20+
21+
# non-pythonic!
1222
def out_params_bad(base: float, args: list):
1323
if len(args) == 0:
1424
args.append(0)

0 commit comments

Comments
 (0)