+ 1
Whats the use of number=3. It works without using it.
4 Réponses
+ 4
Sagar Gyanchandani
Let me explain you the whole code.
# initialization number=3
* initialization of list named as "things"
things=["string",0,[1,2,number],4.56]
* Now where you have typed number in the list . There it will take 3
things=["string",0,[1,2,3],4.56]
Now output time :
print(things[1])
#prints 2nd elements which has index 1 = 0
print(things[2])
#prints 3rd element which has index 2 = [1,2,3]
print(things[2][2])
#prints the 3rd element of 3rd element = 3
I.e. 3rd element of [1,2,3] = 3
You can put 3 instead of number and then you do need to initialize the value of number.
Thanks
+ 3
You can think variable name as a key or a link to it's value.
When
number = 3
And
things = ["string", 0, [1, 2, number], 4.56]
number in the sublist of things. Searches the number's variable, which was 3.
Thus when ever you use things, it is just:
things = ["string", 0, [1, 2, 3]]
+ 1
number = 3
things = ["string", 0, [1, 2, number], 4.56]
print(things[1])
print(things[2])
print(things[2][2])
0
Thanks bro..