0

Output question

What's the output? s='sololearn' print(s[:][:1]) Solution: s Shouldn't the solution be "o" as "o" is index 1? Thanks for any help:).

21st Mar 2019, 1:14 AM
tristach605
tristach605 - avatar
5 Answers
+ 8
tristach605 I believe the answer should be 1 as well. Unless, you change [:1] to just [1]
21st Mar 2019, 1:28 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Diego It is edited.
21st Mar 2019, 1:27 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
list[:1] is not the same as list[1]. list[:1] is equivalent to list[0:1] and means: return a slice of the list starting with index 0, ending with (but not including) index 1. That's why the letter at index 0 (s) is the only letter that is printed
10th Apr 2019, 5:55 AM
Anna
Anna - avatar
+ 4
⚡Prometheus ⚡ Either the post was edited or you posted this in the wrong place.
21st Mar 2019, 1:26 AM
Diego
Diego - avatar
0
Hey Prometheus and Diego. Pardon me as I make a mistake (and have since endited the post). so? any ideas on why this is "s" and not "o"? thanks for any help anyone could procide:).
26th Mar 2019, 10:37 PM
tristach605
tristach605 - avatar