+ 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

9th Jun 2018, 11:08 AM
Ash
3 Réponses
+ 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'''
9th Jun 2018, 11:17 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 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
9th Jun 2018, 11:29 AM
andrey
andrey - avatar
0
What means "sqs" ?
10th Mar 2020, 4:07 PM
Amanda Cortez
Amanda Cortez - avatar