+ 1

Could someone explain what this does and how ?

s="string" s= s[:1] + s[1:]

4th Aug 2018, 2:27 PM
OBAwesome
2 odpowiedzi
+ 10
[start : end : step] is the pythonic way of slicing strings , lists, etc... [:1] = [0:1:1] [1:] = [1:end:1] In your given code it does nothing just slice and join it back to the same thing s[:1] = "s" s[1:] = "tring" s = "s" + "tring" it works same as it works on lists 👇 https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/?ref=app
4th Aug 2018, 4:42 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 1
Thanks
4th Aug 2018, 4:49 PM
OBAwesome