You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/concept/locomotive-engineer/.docs/introduction.md
+14-10Lines changed: 14 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ The special operators `*` and `**` are often used in unpacking contexts and with
9
9
`*<variable_name>` and `**<variable_name>` should not be confused with `*` and `**`. While `*` and `**` are used for multiplication and exponentiation respectively, `*<variable_name>` and `**<variable_name>` are used as packing and unpacking operators.
10
10
~~~~
11
11
12
+
12
13
## Multiple assignment
13
14
14
15
In multiple assignment, the number of variables on the left side of the assignment operator (`=`) must match the number of values on the right side.
@@ -55,6 +56,7 @@ For example:
55
56
56
57
Since `tuples` are immutable, you can't swap elements in a `tuple`.
57
58
59
+
58
60
## Unpacking
59
61
60
62
~~~~exercism/note
@@ -80,9 +82,10 @@ If there are values that are not needed then you can use `_` to flag them:
80
82
"cherry"
81
83
```
82
84
85
+
83
86
### Deep unpacking
84
87
85
-
Unpacking and assigning values from a `list`/`tuple` inside of a `list` or `tuple` (_also known as nested lists/tuples_), works in the same way a shallow unpacking does, but often needs qualifiers to clarify the values context or position:
88
+
Unpacking and assigning values from a `list`/`tuple`enclosed inside a `list` or `tuple` (_also known as nested lists/tuples_) works in the same way a shallow unpacking does — but often needs qualifiers to clarify the context or position:
@@ -238,8 +241,8 @@ This will pack all **key**-**value** pairs from one dictionary into another dict
238
241
### Packing with function parameters
239
242
240
243
When you create a function that accepts an arbitrary number of arguments, you can use [`*args` or `**kwargs`][args and kwargs] in the function definition.
241
-
`*args` is used to pack an arbitrary number of positional (non-keyworded) arguments and
242
-
`**kwargs` is used to pack an arbitrary number of keyword arguments.
244
+
`*args` is used to pack an arbitrary number of positional (_non-keyword_) arguments as a `tuple` and
245
+
`**kwargs` is used to pack an arbitrary number of keyword arguments as a dictionary.
243
246
244
247
Usage of `*args`:
245
248
@@ -355,8 +358,9 @@ Since `zip()` takes multiple iterables and returns a `list` of `tuples` with the
355
358
```
356
359
357
360
[args and kwargs]: https://www.geeksforgeeks.org/args-kwargs-python/
0 commit comments