- 3
Can anyone plz explain me what the hell is the code about
4 Answers
+ 3
List can store numbers, strings, tuple, set, dictionary...etc
+ 1
It's workin'
+ 1
You are just trying to access elements of a list in python through this code.
+ 1
The first print function is printing the value in the array 'things' which is indexed 1 (means second item)
The second print function is printing the value in the array 'things' which is indexed 2 (means third item). As in this array second item is one more array, so it will print the whole array present inside the another array.
The third print function is printing the value in the array 'things' which is indexed 2 (means third item) but it is not only printing the whole third item which is array but also the third item inside the array. That's why two indexes are given things[2][2]
Try this code for simple explanation:
number = 3
things = ["string", [1, 2, number]]
for i in range(len(things)):
for j in range(len(things[i])):
print("things[",i,"][",j,"] = ",things[i][j])