We can create a nested list, like a tuple or dictionary, inside the list, l=[1, 2, 3, [3, 4, 5]]. There are 4 elements and 3 indexes here; 3, 4, and 5 are present in the third index, which is inside the list, so print(l[3][1].

List Slicing


l = [1, 2, 3, ["hello", 3, 4], 5]  # it is mixed list
print(l[3][1])
print(l[0:4])  # it is slicing of the list, note (slicing is as same as in string) here 1 less than 4 i.e. 3 so up-to 3 index will be printed                                                
print(l[0::2])  # : sapce : so, this space is used to print all elements and 2 is increment value
print(l[-1::-1])  # it will print reverse elements, starting from -1 and space is to print all element
# and -1 is the decrement value so it wil print index value -1 than -2 than -3 and so on...

List Iteration

l = [2, 3, 4, 4] 
for n in range(le):
	print(l[n])

for a in l:  # this is second method to print  iteration, the element of l will be passed in a, and it will be printed
	print(a)

for n in range(le):
	print(l[n])

for a in l:  # this is second method to print  iteration, the element of l will be passed in a, and it will be printed
	print(a)

Reverse

for n in range(le - 1, -1, -1):  # list will be started from le-1 index 
# and will be printed till -1 that is till 0 index and last -1 is
# decrement value. Note: as same as string reverse.
	print(n)

List Function:

Delete Function: del (it works on index number),pop(),remove(),clear()

l= [1,2,3,4]
del l[2] # it will delete the element which is present in index 2
print(l)

pop():this function will also remove the element, but it shows what it has removed

l.pop(1) # if we will print it will show
print(l.pop(0))
print(l)

remove(): remove is used to delete the value.

l.remove(3)
print(l)

clear(): it is used to clear the list

l.clear()
print(l)

Update Function: insert(), append() and extends()


l=[2,5,68,]
l[0]=90 #it will update the value of index 0
print(l)