Why different output??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
14th Feb 2019, 7:07 AM
SOUMYA
SOUMYA - avatar
2 Answers
+ 6
In the first case in ur code, you're iterating over a range of indices (even though there is just one). Therefore, list[a:b] returns the result as a list, even if b=a+1. Thus, all you're doing is putting element 3 in a list, then just getting back element 3 from that list. In the below case, you're specifically choosing to get element 3, which will be returned without being put in a list, so from there you access the 0th element of the resulting variable.
14th Feb 2019, 7:35 AM
Arushi Singhania
Arushi Singhania - avatar
+ 5
The same question posted twice, although the code seems to be slightly modified (probably) https://www.sololearn.com/Discuss/1688344/?ref=app
14th Feb 2019, 7:36 AM
Ipang