1 parent 0db5696 commit 600785fCopy full SHA for 600785f
1 file changed
code/ch_09_tuples/_03_methods_with_ref_params.py
@@ -4,11 +4,21 @@
4
def main():
5
args = list()
6
out_params_bad(7, args)
7
- print("Return values (bad): {} & {:.2f}".format(args[0], args[1]))
+ print("Return values (bad): {} & {:.2f}".format(args[0], args[1]))
8
9
# can we do better?
10
+ v1, v2 = out_params(7)
11
+ print("Return values (good): {} & {:.2f}".format(v1, v2))
12
13
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!
22
def out_params_bad(base: float, args: list):
23
if len(args) == 0:
24
args.append(0)
0 commit comments