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

Danny L.
Danny L.
10,837 Points

How would I redo a string like he asks at the end?

At the end of the video he says: "If you need to redo part of a string, you're better off turning it into a list, changing the item, and then joining it back into a string. I bet you can figure out how to do that on your own."

I've gotten this far: '''python alpha_string = "01234v5" list(alpha_string) alpha_list.remove(["v"])

'''

I know I can't delete strings but I couldn't figure out how to do this. Has this been covered already and I just forgot? Sorry I'm really new to Python.

Sorry I tried formatting my code but I can't seem to get it to look right in the post

2 Answers

AJ Salmon
AJ Salmon
5,675 Points

.remove only works on lists, so there's no need to put brackets around the 'v'. Remove the brackets (but leave the parentheses and quotation marks) and it should work!

alpha_list = list(alpha)
alpha_list.remove('v')

Then you can convert it back into a string with:

alpha = "".join(alpha_list)