Python 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
Type "copyright", "credits" or "license" for more information.
IPython 7.8.0 -- An enhanced Interactive Python.
In [1]: testo = "pippo andò al mare"
In [2]: testo[3]
Out[2]: 'p'
In [3]: testo[6:10]
Out[3]: 'andò'
In [4]: testo[-1]
Out[4]: 'e'
In [5]: len(testo)
Out[5]: 18
In [6]: testo[18]
Traceback (most recent call last):
File "<ipython-input-6-e67395f1b25d>", line 1, in <module>
testo[18]
IndexError: string index out of range
In [7]:
In [7]: parola = testo[6:10]
In [8]: parola[2] = 'E'
Traceback (most recent call last):
File "<ipython-input-8-c3a707098240>", line 1, in <module>
parola[2] = 'E'
TypeError: 'str' object does not support item assignment
In [9]:
In [9]: elenco = [ 1, 3, 5, 7, 12, "pippo", 3.6 ]
In [10]: None
In [11]: [ None ] * 3
Out[11]: [None, None, None]
In [12]: elenco[6]
Out[12]: 3.6
In [13]: elenco[7]
Traceback (most recent call last):
File "<ipython-input-13-739728f55da9>", line 1, in <module>
elenco[7]
IndexError: list index out of range
In [14]:
In [14]: elenco[4] = "sostituito"
In [15]: elenco
Out[15]: [1, 3, 5, 7, 'sostituito', 'pippo', 3.6]
In [16]: [1, 2, 3, 4, 5, ]
Out[16]: [1, 2, 3, 4, 5]
In [17]: for indice in range(10):
...: print(indice)
...:
0
1
2
3
4
5
6
7
8
9
In [18]: for indice in range(3,10):
...: print(indice)
...:
3
4
5
6
7
8
9
In [19]: for indice in range(2,10,2):
...: print(indice)
...:
2
4
6
8
In [20]: range(2, 10, 2)
Out[20]: range(2, 10, 2)
In [21]: list(range(2, 10, 2))
Out[21]: [2, 4, 6, 8]
In [22]: pari = list(range(2, 10, 2))
In [23]: pari + pari
Out[23]: [2, 4, 6, 8, 2, 4, 6, 8]
In [24]: pari
Out[24]: [2, 4, 6, 8]
In [25]: _23
Out[25]: [2, 4, 6, 8, 2, 4, 6, 8]
In [26]: ris = _23
In [27]: quadrati = []
...: for x in ris:
...: quadrati = quadrati + [x**2]
...:
In [28]: quadrati = []
...: for x in ris:
...: quadrati += [x**2]
...:
In [29]: for x in range(1, 11):
...: for y in range(1, 11):
...: print(x+y, end=' ')
...: print()
...:
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11 12
4 5 6 7 8 9 10 11 12 13
5 6 7 8 9 10 11 12 13 14
6 7 8 9 10 11 12 13 14 15
7 8 9 10 11 12 13 14 15 16
8 9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18
10 11 12 13 14 15 16 17 18 19
11 12 13 14 15 16 17 18 19 20
In [30]: for x in range(1, 11):
...: for y in range(1, 11):
...: print(x*y, end=' ')
...: print()
...:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
In [31]: for x in range(1, 11):
...: for y in range(1, 11):
...: print(x*y, end='\t')
...: print()
...:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
In [32]: for x in range(1, 11):
...: for y in range(1, 11):
...: prodotto = x*y
...: print(prodotto, end='\t')
...: print()
...:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
In [33]: def area_rettangolo(base, altezza):
...: "Calcoliamo l'area di un rettangolo di data base ed altezza"
...: area = base * altezza
...: return area
...:
In [34]: runfile('/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni/lezione2.py', wdir='/home/andrea/Documents/Uni/Didattica/Prog1/2019-20/Lezioni')
In [35]: