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 = "uno,due,tre,4,cinque"
In [2]: testo.split()
Out[2]: ['uno,due,tre,4,cinque']
In [3]: testo.split(',')
Out[3]: ['uno', 'due', 'tre', '4', 'cinque']
In [4]: testo = "uno,due,tre,,4,cinque"
In [5]: testo.split(',')
Out[5]: ['uno', 'due', 'tre', '', '4', 'cinque']
In [6]: frammenti = testo.split(',')
In [7]: '|'.join(frammenti)
Out[7]: 'uno|due|tre||4|cinque'
In [8]: '|' + '|'.join(frammenti) + '|'
Out[8]: '|uno|due|tre||4|cinque|'
In [8]:
In [8]:
In [9]: '| ' + ' | '.join(frammenti) + ' |'
Out[9]: '| uno | due | tre | | 4 | cinque |'
In [10]: testo2 = "uno , due , tre , quattro"
In [11]: testo2.split(' , ')
Out[11]: ['uno', 'due', 'tre', 'quattro']
In [12]: int("345")
Out[12]: 345
In [13]: int("345ABC")
Traceback (most recent call last):
File "<ipython-input-13-0d6892254660>", line 1, in <module>
int("345ABC")
ValueError: invalid literal for int() with base 10: '345ABC'
In [14]:
In [14]: int("345ABC", 16)
Out[14]: 3431100
In [15]: num = int("345ABC", 16)
In [16]: repr(num, 16)
Traceback (most recent call last):
File "<ipython-input-16-ab8bd462ade2>", line 1, in <module>
repr(num, 16)
TypeError: repr() takes exactly one argument (2 given)
In [17]:
In [17]: " jhskdf ".strip()
Out[17]: 'jhskdf'
In [18]: t = " lihskfjhsk "
In [19]: " URLO !!!".lower()
Out[19]: ' urlo !!!'
In [20]: '0'.isdecimal()
Out[20]: True
In [21]: '8'.isdecimal()
Out[21]: True
In [22]: 'A'.isdecimal()
Out[22]: False
In [23]: 'A'.isnumeric()
Out[23]: False
In [24]: 'A'.isnumeric(16)
Traceback (most recent call last):
File "<ipython-input-24-ace6eccd0944>", line 1, in <module>
'A'.isnumeric(16)
TypeError: isnumeric() takes no arguments (1 given)
In [25]:
In [25]: c = 'A'
In [26]: c.isdigit(16)
Traceback (most recent call last):
File "<ipython-input-26-e36203c3974b>", line 1, in <module>
c.isdigit(16)
TypeError: isdigit() takes no arguments (1 given)
In [27]:
In [27]: "Quo" in " Paperino è al mare con Quo"
Out[27]: True
In [28]: "quo" in " Paperino è al mare con Quo"
Out[28]: False
In [29]: find("Quo"," Paperino è al mare con Quo")
Traceback (most recent call last):
File "<ipython-input-29-92aaa09721c9>", line 1, in <module>
find("Quo"," Paperino è al mare con Quo")
NameError: name 'find' is not defined
In [30]:
In [30]: " Paperino è al mare con Quo".find('mare')
Out[30]: 15
In [31]: " Paperino è al mare con Quo".find('paperina')
Out[31]: -1
In [32]: " Paperino è al mare con Quo".replace('mare', 'montagna')
Out[32]: ' Paperino è al montagna con Quo'
In [33]: testo = " Paperino è al mare con Quo"
In [34]: testo2 = testo.replace('mare','monti')
In [35]: id(testo)
Out[35]: 140332088339864
In [36]: id(testo2)
Out[36]: 140332088339552
In [37]: testo
Out[37]: ' Paperino è al mare con Quo'
In [38]: testo2
Out[38]: ' Paperino è al monti con Quo'
In [39]: x=20
In [40]: y=30
In [41]: lista = ["X:",x,"Y:", y]
In [42]: print(lista)
['X:', 20, 'Y:', 30]
In [43]: lista = ["X:",str(x),"Y:",str( y)]
In [44]: print(lista)
['X:', '20', 'Y:', '30']
In [45]: print(lista.join(' '))
Traceback (most recent call last):
File "<ipython-input-45-82997c3210f6>", line 1, in <module>
print(lista.join(' '))
AttributeError: 'list' object has no attribute 'join'
In [46]:
In [46]: print(' '.join(lista))
X: 20 Y: 30
In [47]: x = 34
In [48]: y = 90
In [49]: lista = ["X:",str(x),"Y:",str( y)]
In [50]: print(' '.join(lista))
X: 34 Y: 90
In [51]: f"X: {x} Y: {y}"
Out[51]: 'X: 34 Y: 90'
In [52]: "X: {} Y: {}".format(x, y)
Out[52]: 'X: 34 Y: 90'
In [53]: testo = " uno due tre uno tre due uno "
In [54]: testo.find('uno')
Out[54]: 1
In [55]: testo.find('uno', 2)
Out[55]: 13
In [56]: testo.find('uno', 14)
Out[56]: 25
In [57]: testo.find('uno', 26)
Out[57]: -1
In [58]: lista = [ 1, 2, 3, 4, 5, 6]
In [59]: lista[5]
Out[59]: 6
In [60]: lista[5] = 45
In [61]: lista
Out[61]: [1, 2, 3, 4, 5, 45]
In [62]: lista + [ 46, 47, 48 ]
Out[62]: [1, 2, 3, 4, 5, 45, 46, 47, 48]
In [63]: lista
Out[63]: [1, 2, 3, 4, 5, 45]
In [64]: lista.append(34)
In [65]: lista
Out[65]: [1, 2, 3, 4, 5, 45, 34]
In [66]: lista.insert(3, 42)
In [67]: lista
Out[67]: [1, 2, 3, 42, 4, 5, 45, 34]
In [68]: lista[4:6]
Out[68]: [4, 5]
In [69]: lista[4:6] = [ "uno", "due", "tre" ]
In [70]: lista
Out[70]: [1, 2, 3, 42, 'uno', 'due', 'tre', 45, 34]
In [71]: lista[:] = [ "uno", "due", "tre" ]
In [72]: lista
Out[72]: ['uno', 'due', 'tre']
In [73]: lista.extend([3, 4, 5, 6])
In [74]: lista
Out[74]: ['uno', 'due', 'tre', 3, 4, 5, 6]
In [75]: lista.copy()
Out[75]: ['uno', 'due', 'tre', 3, 4, 5, 6]
In [76]: L = lista.copy()
In [77]: id(lista)
Out[77]: 140332088241480
In [78]: id(L)
Out[78]: 140332088236040
In [79]: lista.extend([3, 4, 5, 6])
In [80]: lista
Out[80]: ['uno', 'due', 'tre', 3, 4, 5, 6, 3, 4, 5, 6]
In [81]: id(lista)
Out[81]: 140332088241480
In [82]: lista.pop()
Out[82]: 6
In [83]: lista
Out[83]: ['uno', 'due', 'tre', 3, 4, 5, 6, 3, 4, 5]
In [84]: lista.pop(3)
Out[84]: 3
In [85]: lista
Out[85]: ['uno', 'due', 'tre', 4, 5, 6, 3, 4, 5]
In [86]: del lista[5]
In [87]: lista
Out[87]: ['uno', 'due', 'tre', 4, 5, 3, 4, 5]
In [88]: del lista[5:]
In [89]: lista
Out[89]: ['uno', 'due', 'tre', 4, 5]
In [90]: del lista[:]
In [91]: lista
Out[91]: []
In [92]: id(lista)
Out[92]: 140332088241480
In [93]: lista = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
In [94]: lista.index(6)
Out[94]: 5
In [95]: lista.index(66)
Traceback (most recent call last):
File "<ipython-input-95-91d93c56100b>", line 1, in <module>
lista.index(66)
ValueError: 66 is not in list
In [96]:
In [96]: lista.find(66)
Traceback (most recent call last):
File "<ipython-input-96-4069eea48f51>", line 1, in <module>
lista.find(66)
AttributeError: 'list' object has no attribute 'find'
In [97]:
In [97]: lista
Out[97]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [98]: lista.sort()
In [99]: lista
Out[99]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [100]: lista.sort(reverse=True)
...:
In [101]: lista
Out[101]: [9, 8, 7, 6, 5, 4, 3, 2, 1]
In [102]: id(lista)
Out[102]: 140332088262856
In [103]: lista.sort()
In [104]: id(lista)
Out[104]: 140332088262856
In [105]: lista
Out[105]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [106]: lista.copy().sort(reverse=True)
In [107]: l2 = lista.copy()
In [108]: lista
Out[108]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [109]: l2
Out[109]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [110]: l2.sort(reverse=True)
In [111]: l2
Out[111]: [9, 8, 7, 6, 5, 4, 3, 2, 1]
In [112]: lista
Out[112]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [113]: sorted(lista, reverse=True)
Out[113]: [9, 8, 7, 6, 5, 4, 3, 2, 1]
In [114]: lista
Out[114]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [115]: