Commit 4ab38f34 authored by Mathieu Istas's avatar Mathieu Istas
Browse files

minor changes

parent 8959e5ad
Pipeline #83347 failed with stage
in 25 seconds
......@@ -554,7 +554,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.10"
}
},
"nbformat": 4,
......
......@@ -398,26 +398,23 @@
%% Cell type:markdown id: tags:
## `lambda` keyword and anonymous functions
These functions are called anonymous because they are not declared by using the `def` keyword but with the `lambda` keyword so they have not name.
The `lambda` functions are called anonymous because they have no name as they are not declared by using the `def` keyword.
- Lambda forms can take any number of arguments but return just one value in the form of an expression. They cannot contain commands or multiple expressions.
- Lambda form is used in functional programming (but it is usually better to use list comprehension) and for [callbacks in GUI](https://pythonconquerstheuniverse.wordpress.com/2011/08/29/lambda_tutorial/).
%% Cell type:code id: tags:
``` python
f = lambda x, y: x + y
f(1, 2)
print(f(1, 2))
print(f.__name__)
```
%%%% Output: execute_result
3
%% Cell type:markdown id: tags:
## Example of the builtin function `print`
```text
......@@ -431,29 +428,5 @@
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
Type: builtin_function_or_method
```
%% Cell type:code id: tags:
``` python
print('hello', 'Eric')
```
%% Cell type:code id: tags:
``` python
print('hello', 'Eric', sep='_', end='')
print('.')
```
%% Cell type:markdown id: tags:
## Input from Keyboard (builtin function `input`)
%% Cell type:code id: tags:
``` python
answer = input("what's your name ?")
print("your name is ", answer)
```
......
......@@ -122,16 +122,21 @@
%% Cell type:code id: tags:
``` python
# lists comprehensions can be cascaded
[(x,y) for x in [1,2] for y in ['a','b'] ]
```
l1 = [(x,y) for x in [1,2] for y in ['a','b'] ]
print(l1)
%%%% Output: execute_result
# Equivalent without list comprehensions
l2 = []
for x in [1,2]:
for y in ['a','b']:
l2.append((x, y))
[(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]
assert l1 == l2
```
%% Cell type:markdown id: tags:
### Do it yourself (advanced)
......@@ -310,11 +315,11 @@
ns.pop()
```
%%%% Output: execute_result
11
9
%% Cell type:markdown id: tags:
## Complexity :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment