Nested lists

Lists 
can 
be 
included 
within
 
the 
main 
big 
list 
as 
an 
element 
of 
the 
main 
list.
These 
inner 
lists 
are 
called 
"sub-lists"
.
list_name=[item1,[item21,item22,item23],item3,item4]
num_list = [1, 2, [3, 4]]
print(num_list)

Indexing in Nested List

If 
we 
want 
an 
item 
within 
the 
nested 
list 
or 
sublist 
of 
the 
list, 
we 
add 
the 
index 
of 
the 
item 
in 
the 
sublist 
(containing 
the 
item) 
along 
with 
the 
nested 
list/sublist 
index 
number.
list_name[index of sublist containing the item][index of the item in that sublist]
num_list = [1, 2, [3, 4]]
print(num_list[2][0])

list_num = [1, 2, [3, [4, 5]]]
print(list_num[2][1][1])

Adding, Replacing or Deleting values by slicing

Nested 
lists 
can 
be 
added
 
or 
changed
 
within 
a 
list 
by 
slicing 
with 
the 
given 
indices.
#Adding an element to the list using slicing
list_name[starting_index:starting_index]=[value]
We 
can 
replace 
more 
than 
one 
element 
in 
one 
go.
We 
can 
also 
replace 
2 
or 
more 
elements 
with 
a 
lesser 
number 
of 
elements.
list_name[starting_index:ending_index]=[[value1,value2,...]]
Elements 
can 
also 
be 
removed 
from 
a 
list 
with 
the 
help 
of 
slicing.
list_name[starting_index:ending_index]=[]
a = [1, 2, 5, 6]
a[2:2] = [[3, 4]]
#The list [3,4] gets added between the 2nd and 3rd element
print(a)

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

a = [1, 2, 3, 4, 5]
a[1:3] = ['a','b']
print(a)

a = [1, 2, 3, 4, 5]
a[1:3] = ['a']
print(a)

a = [1, 2, 3, 4, 5]
a[1:3] = []
print(a)