Python Forum
How do we print this output?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do we print this output?
#4
The strings are three but your slicing is for a list with at least five elements - [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?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
How do we print this output? - by veve - May-13-2018, 03:59 PM
RE: How do we print this output? - by j.crater - May-13-2018, 04:07 PM
RE: How do we print this output? - by veve - May-14-2018, 12:13 AM
RE: How do we print this output? - by wavic - May-14-2018, 04:30 AM
RE: How do we print this output? - by veve - May-14-2018, 07:40 AM
RE: How do we print this output? - by wavic - May-14-2018, 08:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print not appearing in output dgizzly 1 1,314 Oct-14-2022, 09:55 PM
Last Post: rob101
  Read text file, process data and print specific output Happythankyoumoreplease 3 3,012 Feb-20-2020, 12:19 PM
Last Post: jefsummers
  Need to print the output as follows Mac 2 3,424 Jul-19-2017, 06:52 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020