+ 1
Lists
akash=[1,2,3] akash[2]=akash[0]-1 print(akash[0]) print(akash[2]) print(akash[1]) Can anybody explains it to me plz
3 Respostas
+ 7
list is access by index value and index value start from 0 so first element of list is 1 and so on
akash=[1,2,3]
'''akash[0]=1
akash[1]=2
akash[2]=3'''
akash[2]=akash[0]-1
'''akash[0]=1 and 1-1=0 so akash[2] is assigned 0 so at the time of print 0 will be print '''
print(akash[0])
print(akash[2])
print(akash[1])
'''so output came as
1
0
2'''
+ 1
each element in list has an index, which begin from 0. i.e. in list akash, 1-has index 0; 2-index 1; 3-index 2.
So :
akash[0] =1
akash[1]=2
akash[2]=3
akash[2]= akash[0]-1 means 1-1=0
and akash after that is [1,2,0] so output will be:
1 0 2
0
What means "sqs" ?