Plzzz explain why use [0] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Plzzz explain why use [0]

s = [100,84,63,97] s_sort = s.sort() print(s[::-1][0])

10th Jun 2020, 4:33 AM
Siddhant Saxena
Siddhant Saxena - avatar
2 Answers
+ 2
It first reverses the list and then [0] prints the element at first position
10th Jun 2020, 6:54 AM
Abhay
Abhay - avatar
+ 1
The use of [0] here is meant to only pass the first list item (instead of the list itself) for `print` function to work with. The [0[ specifies the list item index (the first list item's index is zero)
10th Jun 2020, 4:45 AM
Ipang