1
00:00:00,000 --> 00:00:04,480
A function call has two questions to
answer: how do arguments bind to

2
00:00:04,840 --> 00:00:08,800
parameters, and which objects change
during execution?

3
00:00:08,880 --> 00:00:13,760
Its signature controls accepted calls,
including options that must be named.

4
00:00:13,880 --> 00:00:18,720
Its body can mutate a shared input, return
a new object, or reassign a local

5
00:00:18,800 --> 00:00:19,520
name.

6
00:00:19,640 --> 00:00:22,320
Those choices have different effects on
the caller.

7
00:00:22,360 --> 00:00:26,880
We will follow a count filter and a gene
list through actual calls, then explain

8
00:00:26,960 --> 00:00:31,680
why a mutable default can retain state
between calls that appear independent.

9
00:00:32,000 --> 00:00:36,720
The caller supplies the list zero, four,
twelve, and two,

10
00:00:36,800 --> 00:00:39,440
together with a named minimum of four.

11
00:00:39,520 --> 00:00:43,760
The function binds those objects to its
local parameter names and checks that

12
00:00:44,000 --> 00:00:46,520
counts and the threshold are nonnegative.

13
00:00:46,560 --> 00:00:50,920
Its comprehension creates a new list
containing four and twelve.

14
00:00:50,960 --> 00:00:53,960
The return sends that new list back to the
caller.

15
00:00:54,000 --> 00:00:57,893
The input remains zero, four, twelve, and
two.

16
00:00:57,947 --> 00:01:02,160
This function's annotations describe its
intended integer inputs, while the

17
00:01:02,440 --> 00:01:06,320
explicit checks enforce the nonnegative
constraint at runtime.

18
00:01:06,567 --> 00:01:09,980
Before the slash, counts is positional
only.

19
00:01:10,034 --> 00:01:14,007
A caller must supply that list by
position, even though the function uses

20
00:01:14,087 --> 00:01:15,807
the local name counts.

21
00:01:15,847 --> 00:01:20,247
After the star, minimum is keyword only,
so its caller must name the

22
00:01:20,327 --> 00:01:21,074
option.

23
00:01:21,100 --> 00:01:24,447
The default value is one when the caller
omits minimum.

24
00:01:24,487 --> 00:01:29,100
These markers describe argument binding;
they do not change the filtering rule.

25
00:01:29,154 --> 00:01:32,847
They also make an invalid call fail before
the body runs.

26
00:01:32,887 --> 00:01:36,887
A named threshold is especially useful
when several numerical options would

27
00:01:36,967 --> 00:01:38,727
otherwise look interchangeable.

28
00:01:38,967 --> 00:01:42,647
The named threshold call returns four and
twelve.

29
00:01:42,727 --> 00:01:47,127
A second positional argument does not bind
to minimum because the star makes that

30
00:01:47,207 --> 00:01:51,180
parameter keyword only, so Python raises
TypeError.

31
00:01:51,234 --> 00:01:56,007
A named counts argument also raises
TypeError because the slash makes counts

32
00:01:56,127 --> 00:01:57,327
positional only.

33
00:01:57,367 --> 00:02:01,687
These failures come from Python's binding
rules, before the negative-value checks in

34
00:02:01,767 --> 00:02:02,527
the body.

35
00:02:02,567 --> 00:02:06,967
Keep that distinction clear when reading
an error: an invalid calling form and an

36
00:02:07,047 --> 00:02:10,567
invalid data value can require different
corrections.

37
00:02:10,800 --> 00:02:15,520
In a definition, star batches collects
additional positional arguments into a

38
00:02:15,600 --> 00:02:16,400
tuple.

39
00:02:16,440 --> 00:02:21,360
The combine counts function then extends a
new list with each supplied batch.

40
00:02:21,440 --> 00:02:26,400
At a call, star batches performs the
opposite operation: it expands the outer

41
00:02:26,480 --> 00:02:28,720
collection into separate arguments.

42
00:02:28,800 --> 00:02:33,120
The two batches produce three, five, zero,
and eight in that

43
00:02:33,200 --> 00:02:33,840
order.

44
00:02:33,920 --> 00:02:38,560
Dictionary unpacking with a double star
supplies named options, so a minimum of

45
00:02:38,640 --> 00:02:40,960
five keeps five and eight.

46
00:02:41,040 --> 00:02:45,600
A misspelled option raises TypeError
unless the function explicitly accepts

47
00:02:45,680 --> 00:02:47,600
arbitrary keyword arguments.

48
00:02:47,833 --> 00:02:52,713
The caller name refers to one list
containing T P fifty three and B R

49
00:02:52,793 --> 00:02:54,020
C A one.

50
00:02:54,046 --> 00:02:58,193
The local parameter genes refers to that
same list during the call.

51
00:02:58,233 --> 00:03:01,753
Python does not copy the list when it
binds the parameter.

52
00:03:01,913 --> 00:03:06,393
Appending a marker changes the shared
object, so the caller now sees flagged as

53
00:03:06,553 --> 00:03:07,646
a third entry.

54
00:03:07,700 --> 00:03:11,993
The function returns the same list, but
the mutation has already happened before

55
00:03:12,073 --> 00:03:13,193
that return.

56
00:03:13,353 --> 00:03:16,273
Returning None instead would not undo the
change.

57
00:03:16,313 --> 00:03:19,833
State mutation explicitly in a function's
contract.

58
00:03:20,067 --> 00:03:23,907
Start with the same two gene labels in
another input list.

59
00:03:24,067 --> 00:03:28,867
Concatenation creates a new list that also
contains rebound, and the assignment

60
00:03:28,947 --> 00:03:32,494
makes the local name genes refer to that
new list.

61
00:03:32,520 --> 00:03:36,347
The caller retains its reference to the
original two-entry list.

62
00:03:36,387 --> 00:03:40,440
To use the new result, the caller must
keep the return value.

63
00:03:40,494 --> 00:03:44,947
This example therefore separates a local
assignment from a change to an existing

64
00:03:45,427 --> 00:03:45,934
object.

65
00:03:45,960 --> 00:03:50,467
An expression such as an augmented
assignment needs its own analysis because

66
00:03:50,547 --> 00:03:53,347
its behavior depends on the object's type.

67
00:03:53,567 --> 00:03:58,447
The default expression, an empty list, is
evaluated when Python executes the

68
00:03:58,527 --> 00:03:59,887
function definition.

69
00:03:59,967 --> 00:04:04,847
The first call that omits seen appends T P
fifty three to that list.

70
00:04:04,927 --> 00:04:09,887
The second call also omits seen, so it
receives the same list and appends E G

71
00:04:09,967 --> 00:04:10,847
F R.

72
00:04:10,927 --> 00:04:13,380
Its result contains both labels.

73
00:04:13,434 --> 00:04:18,287
The safe form uses None as the default and
creates a list inside the call when the

74
00:04:18,527 --> 00:04:19,607
argument is None.

75
00:04:19,647 --> 00:04:23,807
Each omitted argument then produces a
separate list, while an explicitly

76
00:04:23,887 --> 00:04:26,687
supplied list remains shared by design.

77
00:04:26,933 --> 00:04:31,013
The argument description should state the
permitted values and whether the function

78
00:04:31,093 --> 00:04:33,280
expects a mutable collection.

79
00:04:33,306 --> 00:04:37,413
The return description should say whether
the caller receives a new object or the

80
00:04:37,493 --> 00:04:39,706
same object after a change.

81
00:04:39,760 --> 00:04:43,253
The error description should name the
invalid conditions that the function

82
00:04:43,333 --> 00:04:44,253
checks.

83
00:04:44,293 --> 00:04:48,933
Google style docstrings organize those
details under Args, Returns, and

84
00:04:49,213 --> 00:04:50,853
Raises when they apply.

85
00:04:50,933 --> 00:04:55,253
Type annotations help a static checker,
but they do not automatically validate a

86
00:04:55,373 --> 00:04:59,813
list's elements or enforce a numerical
bound during a normal Python call.

87
00:05:00,033 --> 00:05:04,753
Before executing a call, bind each
supplied argument to its parameter and

88
00:05:04,833 --> 00:05:07,753
identify the objects shared with the
caller.

89
00:05:07,793 --> 00:05:12,313
After the call, compare both the return
value and the original input.

90
00:05:12,353 --> 00:05:17,073
A new outer list does not necessarily copy
its nested objects, so include

91
00:05:17,153 --> 00:05:20,006
nested data when that distinction matters.

92
00:05:20,060 --> 00:05:24,593
For default arguments, call the function
more than once and test both omission and

93
00:05:24,633 --> 00:05:27,046
an explicitly supplied collection.

94
00:05:27,100 --> 00:05:32,033
The written exercises combine keyword
unpacking, filtering, independent result

95
00:05:32,393 --> 00:05:34,873
lists, and a supplied mutable list.

96
00:05:34,913 --> 00:05:38,593
Explain each object relationship before
checking the answer.
