Class 12th Python Lecture 5
Class 12th Python Lecture 5
L = list(‘LockDown’)
print(L) [‘L’, ‘o’, ‘c’, ‘k’, ‘D’, ‘o’, ‘w’, ‘n’]
Differences :
Storage : Strings store single character at each block, Lists store references.
Mutability : Strings-Immutable Lists-Mutable
Playing with Lists
■ Appending Elements ■ Extending Elements
L=[2,5,17] L = [2,5,17]
L[3]=12 or L.append(12) L.extend( (21, ‘hi’, [3,6,7]) )
■ Updating Elements
L[1]=7
■ Deleting Elements
del L[2] deletes element at index 2.
del L[1:4] deletes slice of 1:4 i.e. 1,2 & 3 indices.
del L deletes the whole list.
Playing with Lists (other operations are same as strings)
■ Making a True Copy
L2 = Colors ❌
L2 = list(Colors) ✔
In first case, any changes in Colors will reflect in L2 as they both are
referencing the same list.
Lists Functions
Python also offers many built in functions for Lists.
OUTPUT : 1*2*A*B
Tuple Functions
● The len method (same for string & List too)
len(<tuple>) returns length of the tuple.