Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-12-13 15:36:09 +01:00 committed by GitHub
parent 0ec48eb1fb
commit 657e9b0d88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -304,7 +304,7 @@ a: 4
b: 5 b: 5
``` ```
[Unpacking Argument Lists](https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists) ## [Unpacking Argument Lists](https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists)
```python ```python
def f(a: int, b: int, c: int, d: int) -> int: def f(a: int, b: int, c: int, d: int) -> int:
@ -324,3 +324,29 @@ print(f(2, *my_tuple_c)) # -> 120
``` ```
## Documentation strings ## Documentation strings
## [Lambda expressions / anonymous functions](https://docs.python.org/3/reference/expressions.html#lambda)
```python
lambda_expr ::= "lambda" [parameter_list] ":" expression
```
> Lambda expressions (sometimes called lambda forms) are used to create anonymous functions. The expression lambda parameters: expression yields a function object. The unnamed object behaves like a function object defined with:
```python
def <lambda>(parameters):
return expression
```
Example 1:
```python
pairs = [(1, "one"), (2, "two"), (3, "three"), (4, "four")]
def f(x):
return x[1]
print(pairs) # -> [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
print((lambda x: x[1])(pairs)) # -> (2, 'two')
print(f(pairs)) # -> (2, 'two')
```