List Flashcards
t = [“d”,”c”,”e”,”b”,”a”]
t.sort()
t
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
t = [“a”,”b”,”c”]
t.append(“d”)
t
[‘a’, ‘b’, ‘c’, ‘d’]
t1 = [“a”,”b”,”c”]
t2= [“d”,”e”]
t1.extend(t2)
t1
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
t=[“a”,”b”,”c”,”d”,”e”,”f”]
t[1:3] = [“x”,”y”]
t
[‘a’, ‘x’, ‘y’, ‘d’, ‘e’, ‘f’]
t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[:]
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]
t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[1:3]
[‘b’, ‘c’]
t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[:4]
[‘a’, ‘b’, ‘c’, ‘d’]
t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[3:]
[‘d’, ‘e’, ‘f’]
[1,2,3]*3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
[0] *4
[0, 0, 0, 0]
a = [1,2,3]
b = [4,5,6]
c = a+b
c
[1, 2, 3, 4, 5, 6]
number=[42,5]
for i in range(len(number)):
number[i] = number[i] * 2
print(number)
[84,10]
number=[42,5]
42 in number
123 in number
5 in number
TRUE
FALSE
TRUE
for cheese in cheeses:
print(cheese)
Cheddar
Edam
Gouda
Wil print without []
t = t.sort()
t
Return None and modify the List to empty list and if you try again you’ll get none type error because you are sorting empty list.