+ 5

number = 3 things = ["string", 0, [1, 2, number], 4.56] print(things[1]) print(things[2]) print(things[2][2])

I can't understand above code😌😌😌😟😟😟.. please tell me and like it 😎😁😁😂

19th Mar 2017, 5:53 AM
🎆Sourav Subhakant Dash🔥🔥
🎆Sourav Subhakant Dash🔥🔥 - avatar
2 Antworten
+ 1
The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that items in a list need not be of the same type.
19th Mar 2017, 3:54 PM
jms95
jms95 - avatar
0
Dude.. Ekdum simple Basically u can store any type of data in a list Here, 'things' is a list.. Which is storing 1st a string, double quotes mein "string" Then a number, '0' here Then it is storing another list, yep another list, can store anything.. Which is [1,2,number].. Number=3, mentioned in 1st line.. Last element in our list 'things' is a float.. 4.56 Now about accessing data in a list.. Just like array, we use indices.. Eg: things[0] means the 0th element, which is actually the 1st element of list.. Here the 1st element is "string" Now in the code, that explains the 1st & 2nd print statements.. Things[1] is '0' & things[2] is the 3rd element of our list, which incidentally here is another list.. So o/p will be [1,2,3] Now for the last print statement.. What if, in the 2nd print statement, I don't want to print the entire list [1,2,3]... What if I only want to print the last element, here being '3'...so basically, how would I refer only this element.. This is list within list.. So things[2][2]..means choose the 3rd element( element at 2 index) of my list "things", which is a list here & then within that list also, choose only the 3rd element ( element at 2 index).. Which is "3" here Hope I was able to explain.. Sorry for the overly long answer
19th Mar 2017, 7:00 PM
dushyant Chauhan