Lists

Declaring basic list

basicList = [10, 20, 30, 40]

Nesting lists

basicList = ['spam', 2.0, 5, [10, 20]]
print(basicList[0]) # spam

Traversing list

cheeses = ['Cheddar', 'Edam', 'Gouda']
for cheese in cheeses:
	print(cheese)

Ranging through list with index

cheeses = ['Cheddar', 'Edam', 'Gouda']                                                                                                        
                                                                                                                                              
for i in range(len(cheeses)):                                                                                                                 
    print(i, cheeses[i])

Concatenate two lists

a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
print(c)

List method - append

t = ['a', 'b', 'c']
t.append('d')
print(t)

List method - extend

t1 = ['a', 'b', 'c']
t2 = ['d', 'e', 'f']

#t2 remains unmodified.

t1.extend(t2)
print(t1)

List method - sort

t = ['d', 'c', 'e', 'b', 'a']
t.sort()
print(t)