简体   繁体   中英

Python replace to get rid of white space not working

I'm trying to get rid of spaces in a string using python's replace(), but it doesn't seem to be working. Looking at past questions, most people have the issue of not catching the new string that is returned by the function, but I'm doing that. I'm not sure what else could be wrong.

My code looks like:

teamname = "University of Alabama"
teamname = teamname.replace(' ','')
print teamname

This should return "UniversityofAlabama", but instead it gives "University of Alabama" right back to me. Any ideas?

Split it into a list then join it back together.

teamname = "University of Alabama"
teamname = teamname.split()
print teamname.join()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM