Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types Deletion

What if I want to delete a word from a string?

To see if I got this right, if I want to delete a whole word from a string, I should convert the string to a list, remove all the letters individually and after convert the list back into a string?

1 Answer

str = "this is your string"
words = str.split()
words.remove(words[0])

this will remove the first word the default behavior of split() is to split the string on every white space, the returned value is a list containing the 'words'

Not sure we worked with index up to this video, but if we did, thx. Looks ok to me.