Python Lists
kodingwindow@kw:~$ python3
...
>>> a=[1, 2, 3, 4, 5, 6]
>>> a[2:5]
[3, 4, 5]

>>> a[2:10]
[3, 4, 5, 6]

>>> a[:]
[1, 2, 3, 4, 5, 6]

>>> a
[1, 2, 3, 4, 5, 6]

>>> strings=['Thomson','1010011','999.99','A1D3T6Z'] >>> strings[0] 'Thomson' >>> strings[3] 'A1D3T6Z' >>> strings[-1] 'A1D3T6Z' >>> strings[-4] 'Thomson' >>> len(strings) 4 >>> strings[0]='Neil' >>> strings[0] 'Neil' >>> strings[-4] 'Neil' >>> strings ['Neil', '1010011', '999.99', 'A1D3T6Z'] >>> del strings[3] >>> strings ['Neil', '1010011', '999.99'] >>> strings.append('Edison') >>> strings ['Neil', '1010011', '999.99', 'Edison'] >>> strings.reverse() >>> strings ['Edison', '999.99', '1010011', 'Neil'] >>> strings.sort() >>> strings ['1010011', '999.99', 'Edison', 'Neil'] >>> strings.insert(2,'Linus') >>> strings ['1010011', '999.99', 'Linus', 'Edison', 'Neil'] >>> strings.remove('999.99') >>> strings ['1010011', 'Linus', 'Edison', 'Neil'] >>> strings+[1,2,3,4] ['1010011', 'Linus', 'Edison', 'Neil', 1, 2, 3, 4] >>> strings ['1010011', 'Linus', 'Edison', 'Neil'] >>> list(strings) ['1010011', 'Linus', 'Edison', 'Neil'] >>> list('strings') ['s', 't', 'r', 'i', 'n', 'g', 's'] >>> 'neil' in strings False >>> 'Neil' in strings True >>> 'Thomson' not in strings True >>> strings.pop(0) '1010011' >>> strings ['Linus', 'Edison', 'Neil'] >>> del strings[2] >>> strings ['Linus', 'Edison']
Advertisement