Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- spam = ['ciao', 'a', 'b']
- spam[-2] #element a
- spam[1:3] #element 1 e 2
- spam[1:] #tutti gli element a parte lo 0
- spam[:1} #solo l'elemento 0
- del spam[1]
- len(spam) #number of elements
- [1,2,3] + [3,4] #[1, 2, 3, 3, 4}
- [1, 2} * 3 #[3, 6]
- list('Hello') #crea una lista H, e, l, l, o
- 'ciao' in spam #evaluates to True or False wether or not 'ciao' is present in the container
- ##############################################
- print(list(range(100))) #list 0:99
- spam = ['a', 'b', 'c']
- #iterate through elements of a list
- for i in range(len(spam)) :
- print('index ' + str(i) + ' value ' + spam[i])
- #assignment for list
- size, color, name = spam
- size, color, name = 'skinny', 'black', 'quiet'
- #swap environment variable values
- a = 'aaa'
- b = 'bbb'
- a, b = b, a
- ##############################################
- spam.index['a']
- spam.append['b']
- spam.insert(1, 'bla')
- spam.remove('bla')
- del spam[0]
- spam.sort()
- spam.sort(reverse=True)
- spam.sort(key=str.lower) #case insensitive sorting
- #strings: similar to list
- ##when strings get assigned they get copied. This is not true for list!! When the
- ##list gets assigned we are only copying the reference!!
- #This is true also when calling functions!! List (mutable data) as a parameter
- #is taken by reference. String is instead copied
- #To force the copy of a mutable object
- import copy
- copy.deepcopy(spam)
Advertisement
Add Comment
Please, Sign In to add comment