May-14-2018, 04:30 AM
The strings are three but your slicing is for a list with at least five elements -
"Today is a sunny day, let go to picnic" will become a two element list since it has only one comma.
[0:4]
. "Today is a sunny day, let go to picnic" will become a two element list since it has only one comma.
>>> s1 = "Today is a sunny day, let go to picnic" >>> s1 = s1.split(',') >>> s1 ['Today is a sunny day', ' let go to picnic'] >>> s1[0:4] ['Today is a sunny day', ' let go to picnic'] >>> print(s1[0:4]) ['Today is a sunny day', ' let go to picnic'] >>>What is the output you want to print?