Skip to content

Commit 5eec277

Browse files
committed
Change ex4 class name and switch function name
1 parent 99a9b4a commit 5eec277

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Doc/faq/programming.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,13 @@ desired effect in a number of ways.
518518

519519
1) By returning a tuple of the results::
520520

521-
>>> def func2(a, b):
521+
>>> def func1(a, b):
522522
... a = 'new-value' # a and b are local names
523523
... b = b + 1 # assigned to new objects
524524
... return a, b # return new values
525525
...
526526
>>> x, y = 'old-value', 99
527-
>>> func2(x, y)
527+
>>> func1(x, y)
528528
('new-value', 100)
529529

530530
This is almost always the clearest solution.
@@ -533,12 +533,12 @@ desired effect in a number of ways.
533533

534534
3) By passing a mutable (changeable in-place) object::
535535

536-
>>> def func1(a):
536+
>>> def func2(a):
537537
... a[0] = 'new-value' # 'a' references a mutable list
538538
... a[1] = a[1] + 1 # changes a shared object
539539
...
540540
>>> args = ['old-value', 99]
541-
>>> func1(args)
541+
>>> func2(args)
542542
>>> args
543543
['new-value', 100]
544544

@@ -555,16 +555,16 @@ desired effect in a number of ways.
555555

556556
5) Or bundle up values in a class instance::
557557

558-
>>> class argSetter:
558+
>>> class Namespace:
559559
... def __init__(self, /, **args):
560560
... for key, value in args.items():
561561
... setattr(self, key, value)
562562
...
563563
>>> def func4(args):
564-
... args.a = 'new-value' # args is a mutable argSetter
564+
... args.a = 'new-value' # args is a mutable Namespace
565565
... args.b = args.b + 1 # change object in-place
566566
...
567-
>>> args = argSetter(a='old-value', b=99)
567+
>>> args = Namespace(a='old-value', b=99)
568568
>>> func4(args)
569569
>>> vars(args)
570570
{'a': 'new-value', 'b': 100}

0 commit comments

Comments
 (0)