Print word from list
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Aug 3 18:35:32 EDT 2013
On Sat, 03 Aug 2013 15:17:42 -0700, eschneider92 wrote:
> pie='apple keylime pecan meat pot cherry'
That sets pie to a string containing multiple words.
> pie.split()
This splits pie into individual words, then immediately throws the result
away, leaving pie still set to a string. Instead, you want to do this:
pie = pie.split()
Now pie will be a list of individual words. You can print the entire list:
print(pie)
or print each word separately:
for filling in pie:
print(filling)
Or pick out one specific filling:
print(pie[2]) # should print 'pecan'
--
Steven
More information about the Python-list
mailing list