Commit 23ca5c46 authored by Alessandro CERIONI's avatar Alessandro CERIONI
Browse files

Overall update

parent 120c0cc8
......@@ -65,14 +65,14 @@
%%%% Output: error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-465e48023fdd> in <module>()
<ipython-input-4-48a28808618d> in <module>
----> 1 "Hello" + 1
TypeError: Can't convert 'int' object to str implicitly
TypeError: can only concatenate str (not "int") to str
%% Cell type:markdown id: tags:
* d'une **gestion automatique de la mémoire par ramasse-miettes** et
* d'un **système de gestion d'exceptions** ; il est ainsi similaire à Perl, Ruby, Scheme, Smalltalk et Tcl.
......@@ -85,11 +85,11 @@
%%%% Output: error
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-11-05c9758a9c21> in <module>()
<ipython-input-5-9e1622b385b6> in <module>
----> 1 1/0
ZeroDivisionError: division by zero
%% Cell type:code id: tags:
......@@ -108,11 +108,11 @@
%% Cell type:markdown id: tags:
* Crée par Guido van Rossum, au "Centrum voor Wiskunde en Informatica" d'Amsterdam
* 20 février 1991 : première version, v. 0.9.0
* Décembre 2008 : publication de la version 3.0
* 25 mars 2019 : publication de la version 3.7.3 (la plus recente au jour d'aujourd'hui)
* 24 février 2020 : publication de la version 3.8.2
%% Cell type:markdown id: tags:
# Licence
......
......@@ -48,11 +48,10 @@
'_i2',
'_ih',
'_ii',
'_iii',
'_oh',
'_sh',
'a',
'b',
'exit',
'get_ipython',
'quit']
......@@ -76,11 +75,11 @@
%%%% Output: error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-4-a8a78d0ff555> in <module>()
<ipython-input-4-3a710d2a84f8> in <module>
----> 1 z
NameError: name 'z' is not defined
%% Cell type:markdown id: tags:
......
......@@ -272,10 +272,11 @@
'__getitem__',
'__getnewargs__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mod__',
......@@ -302,10 +303,11 @@
'format',
'format_map',
'index',
'isalnum',
'isalpha',
'isascii',
'isdecimal',
'isdigit',
'isidentifier',
'islower',
'isnumeric',
......@@ -371,60 +373,66 @@
### Formatage de chaînes de caractères
%% Cell type:code id: tags:
``` python
"Oui, %s!" % (b) # old style
"Oui, %s!" % (b) # very old style
```
%%%% Output: execute_result
'Oui, ceci est une chaîne de caractères!'
%% Cell type:code id: tags:
``` python
"Oui, {0}!".format(b) # new style
"Oui, {0}!".format(b) # old style, Python 2.6+
```
%%%% Output: execute_result
'Oui, ceci est une chaîne de caractères!'
%% Cell type:code id: tags:
``` python
"{0}, {1}!".format("Oui", b)
"{0}, {1}!".format("Oui", b)
```
%%%% Output: execute_result
'Oui, ceci est une chaîne de caractères!'
%% Cell type:code id: tags:
``` python
"Voici un numéro avec 3 chiffres décimaux: %.3f" % (1.23456)
f"Oui, {b}!" # new style, Python 3.6+
```
%%%% Output: execute_result
'Voici un numéro avec 3 chiffres décimaux: 1.235'
'Oui, ceci est une chaîne de caractères!'
%% Cell type:code id: tags:
``` python
my_num = 1.23456
```
%% Cell type:code id: tags:
``` python
"Voici un numéro avec 3 chiffres décimaux: {0:.4}".format(1.23456)
f"Voici un numéro avec 3 chiffres décimaux: {my_num:.3f}"
```
%%%% Output: execute_result
'Voici un numéro avec 3 chiffres décimaux: 1.235'
%% Cell type:markdown id: tags:
Pour plus d'info, cf. https://pyformat.info/
Pour plus d'info, cf. https://pyformat.info/, https://realpython.com/python-f-strings/
%% Cell type:markdown id: tags:
## Conversions
......@@ -440,11 +448,11 @@
%%%% Output: error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-44-f96fb8f649b6> in <module>()
<ipython-input-35-bd58363a63fc> in <module>
----> 1 a + b
TypeError: unsupported operand type(s) for +: 'int' and 'str'
%% Cell type:code id: tags:
......@@ -520,5 +528,11 @@
```
%%%% Output: execute_result
False
%% Cell type:code id: tags:
``` python
```
......
......@@ -167,11 +167,11 @@
%%%% Output: error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-15-b8a599b53150> in <module>()
<ipython-input-26-f1ce1e829ae5> in <module>
----> 1 c.append(4)
AttributeError: 'tuple' object has no attribute 'append'
%% Cell type:code id: tags:
......@@ -209,10 +209,11 @@
'__getitem__',
'__getnewargs__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mul__',
......@@ -274,14 +275,14 @@
%%%% Output: error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-17371c6688f6> in <module>()
<ipython-input-33-123a9cc6df61> in <module>
----> 1 d[0]
TypeError: 'set' object does not support indexing
TypeError: 'set' object is not subscriptable
%% Cell type:code id: tags:
``` python
for index, el in enumerate(d):
......@@ -579,11 +580,11 @@
{**e, **f}
```
%%%% Output: execute_result
{1: 'value1', 'key1': 'value1', 'key2': 'une autre valeur'}
{'key1': 'value1', 'key2': 'une autre valeur', 1: 'value1'}
%% Cell type:markdown id: tags:
Mais... il faut faire attention !!!
......@@ -593,11 +594,11 @@
{**f, **e}
```
%%%% Output: execute_result
{1: 'value1', 'key1': 'value1', 'key2': 'value2'}
{1: 'value1', 'key2': 'value2', 'key1': 'value1'}
%% Cell type:code id: tags:
``` python
{**f, **e} == {**e, **f}
......@@ -620,11 +621,11 @@
e
```
%%%% Output: execute_result
{1: 'value1', 'key1': 'value1', 'key2': 2}
{'key1': 'value1', 'key2': 2, 1: 'value1'}
%% Cell type:code id: tags:
``` python
e = {'key1': 'value1', 'key2': 'value2'}
......@@ -633,18 +634,6 @@
f
```
%%%% Output: execute_result
{1: 'value1', 'key1': 'value1', 'key2': 'value2'}
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
{1: 'value1', 'key2': 'value2', 'key1': 'value1'}
......
......@@ -114,74 +114,74 @@
id(a)
```
%%%% Output: execute_result
94429569188288
9302176
%% Cell type:code id: tags:
``` python
id(1)
```
%%%% Output: execute_result
94429569188288
9302176
%% Cell type:code id: tags:
``` python
b = a
id(b)
```
%%%% Output: execute_result
94429569188288
9302176
%% Cell type:code id: tags:
``` python
a = 2
id(a)
```
%%%% Output: execute_result
94429569188320
9302208
%% Cell type:code id: tags:
``` python
id(2)
```
%%%% Output: execute_result
94429569188320
9302208
%% Cell type:code id: tags:
``` python
id(b)
```
%%%% Output: execute_result
94429569188288
9302176
%% Cell type:code id: tags:
``` python
b += 4
id(b)
```
%%%% Output: execute_result
94429569188416
9302304
%% Cell type:code id: tags:
``` python
b
......@@ -197,11 +197,11 @@
id(5)
```
%%%% Output: execute_result
94429569188416
9302304
%% Cell type:markdown id: tags:
### Avec les types complexes :
......@@ -212,22 +212,22 @@
id(a)
```
%%%% Output: execute_result
140403088829704
139846274206288
%% Cell type:code id: tags:
``` python
b = a
id(b)
```
%%%% Output: execute_result
140403088829704
139846274206288
%% Cell type:code id: tags:
``` python
a.append(3)
......@@ -240,22 +240,22 @@
id(a)
```
%%%% Output: execute_result
140403088829704
139846274206288
%% Cell type:code id: tags:
``` python
print(b)
id(b)
```
%%%% Output: execute_result
140403088829704
139846274206288
%% Cell type:markdown id: tags:
$\Rightarrow$ _shallow copy_ par défaut
......@@ -371,11 +371,5 @@
```
%%%% Output: execute_result
{'key1': 'value1', 'key2': 'value2'}
%% Cell type:code id: tags:
``` python
```
......
......@@ -140,14 +140,14 @@
%%%% Output: error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-4a91147fc633> in <module>()
<ipython-input-12-8c7890b5a99f> in <module>
----> 1 hello_world("2")
<ipython-input-11-93f09d33c8f7> in hello_world(n)
<ipython-input-10-6ece3cdf1a2b> in hello_world(n)
1 def hello_world( n: int ) -> str:
2
----> 3 return "Hello world! " * n
TypeError: can't multiply sequence by non-int of type 'str'
......@@ -204,11 +204,11 @@
return a+b
```
%%%% Output: error
File "<ipython-input-18-6ab00fbf97c2>", line 1
File "<ipython-input-17-7e1ef5ad4f7a>", line 1
def add(a=10, b):
^
SyntaxError: non-default argument follows default argument
%% Cell type:markdown id: tags:
......@@ -345,11 +345,5 @@
```
%%%% Output: execute_result
['apple', 'orange', 'raspberry']
%% Cell type:code id: tags:
``` python
```
......
......@@ -26,16 +26,16 @@
self.age += 1
def __str__(self):
return """
Name: %s
Surname: %s
Age: %i
""" % (self.name, self.surname, self.age)
return f"""
Name: {self.name}
Surname: {self.surname}
Age: {self.age}
"""
def __repr__(self):
return "Voici à quoi ça sert !"
```
......@@ -101,10 +101,11 @@
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
......
......@@ -106,11 +106,11 @@
os.getcwd()
```
%%%% Output: execute_result
'/home/acerioni/Documents/ClubDevAnonymes/20190515_Python'
'/home/acerioni/devel/python101'
%% Cell type:code id: tags:
``` python
os.path.join('voici', 'un', 'chemin', 'de', 'acces')
......@@ -131,25 +131,10 @@
```
%% Cell type:code id: tags:
``` python
sys.getwindowsversion()
```
%%%% Output: error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-131-a1416e8c9c76> in <module>()
----> 1 sys.getwindowsversion()
AttributeError: module 'sys' has no attribute 'getwindowsversion'
%% Cell type:code id: tags:
``` python
sys.getdefaultencoding()
```
%%%% Output: execute_result
......@@ -161,13 +146,13 @@
sys.argv
```
%%%% Output: execute_result
['/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py',
['/home/acerioni/devel/python101/venv/lib/python3.7/site-packages/ipykernel_launcher.py',
'-f',
'/run/user/1000/jupyter/kernel-943af524-2958-41db-898d-3c7e42ea734b.json']
'/home/acerioni/.local/share/jupyter/runtime/kernel-63d60470-7896-4dbd-874f-7c6a76e3aed6.json']
%% Cell type:markdown id: tags:
## [time](https://docs.python.org/3/library/time.html)
......@@ -183,11 +168,11 @@
time.time()
```
%%%% Output: execute_result
1557918857.9943986
1583792633.057946
%% Cell type:code id: tags:
``` python
start = time.time()
......@@ -216,11 +201,11 @@
dt
```
%%%% Output: execute_result
datetime.datetime(2019, 5, 15, 13, 14, 20, 211075)
datetime.datetime(2020, 3, 9, 23, 23, 55, 97904)
%% Cell type:code id: tags:
``` python
print(dt)
......@@ -232,11 +217,11 @@
dt.year
```
%%%% Output: execute_result
2019
2020
%% Cell type:code id: tags:
``` python
type(dt)
......@@ -273,21 +258,21 @@
dt2
```
%%%% Output: execute_result
datetime.datetime(2019, 5, 15, 13, 14, 20, 340889, tzinfo=<DstTzInfo 'Europe/Paris' CEST+2:00:00 DST>)
datetime.datetime(2020, 3, 9, 23, 23, 55, 153883, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>)
%% Cell type:code id: tags:
``` python
dt2.tzinfo
```
%%%% Output: execute_result
<DstTzInfo 'Europe/Paris' CEST+2:00:00 DST>
<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>
%% Cell type:code id: tags:
``` python
print(dt2)
......@@ -398,11 +383,11 @@
str(my_dict)
```
%%%% Output: execute_result
"{'key2': 2, 'key1': 'value1'}"
"{'key1': 'value1', 'key2': 2}"
%% Cell type:markdown id: tags:
...mais le paquet `json` offre des fonctionnalités supplémentaires. Ex. :
......@@ -487,11 +472,11 @@
%% Cell type:code id: tags:
``` python
with open('my_dict.yaml', 'r') as fp:
my_dict = yaml.load(fp)
my_dict = yaml.full_load(fp)
```