@@ -518,13 +518,13 @@ desired effect in a number of ways.
518
518
519
519
1) By returning a tuple of the results::
520
520
521
- >>> def func2 (a, b):
521
+ >>> def func1 (a, b):
522
522
... a = 'new-value' # a and b are local names
523
523
... b = b + 1 # assigned to new objects
524
524
... return a, b # return new values
525
525
...
526
526
>>> x, y = 'old-value', 99
527
- >>> func2 (x, y)
527
+ >>> func1 (x, y)
528
528
('new-value', 100)
529
529
530
530
This is almost always the clearest solution.
@@ -533,12 +533,12 @@ desired effect in a number of ways.
533
533
534
534
3) By passing a mutable (changeable in-place) object::
535
535
536
- >>> def func1 (a):
536
+ >>> def func2 (a):
537
537
... a[0] = 'new-value' # 'a' references a mutable list
538
538
... a[1] = a[1] + 1 # changes a shared object
539
539
...
540
540
>>> args = ['old-value', 99]
541
- >>> func1 (args)
541
+ >>> func2 (args)
542
542
>>> args
543
543
['new-value', 100]
544
544
@@ -555,16 +555,16 @@ desired effect in a number of ways.
555
555
556
556
5) Or bundle up values in a class instance::
557
557
558
- >>> class argSetter :
558
+ >>> class Namespace :
559
559
... def __init__(self, /, **args):
560
560
... for key, value in args.items():
561
561
... setattr(self, key, value)
562
562
...
563
563
>>> def func4(args):
564
- ... args.a = 'new-value' # args is a mutable argSetter
564
+ ... args.a = 'new-value' # args is a mutable Namespace
565
565
... args.b = args.b + 1 # change object in-place
566
566
...
567
- >>> args = argSetter (a='old-value', b=99)
567
+ >>> args = Namespace (a='old-value', b=99)
568
568
>>> func4(args)
569
569
>>> vars(args)
570
570
{'a': 'new-value', 'b': 100}
0 commit comments