[Tutor] Fwd: Re: python question

Alan Gauld alan.gauld at yahoo.co.uk
Mon Nov 2 07:06:26 EST 2020


Don't know what's up with my network but this is my third attempt to
send this.

Sorry if you wind up with multiple copies!


On 02/11/2020 07:55, jasmine wrote:
> Hi,
> How do I allow a user to input an arbitrary number of names?


Just get them to enter a string then you have to break that
string into it's elements.

s = input("Enter some names: ")
names = s.split() # assuming names are separated by whitespace
names = s.split(',') # assuming they are separated by commas
names = s.split(',:;. ') # assuming separated by any of specified chars

HTH

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list