0

Removing certain substrings from strings -Python

I want to remove all spaces from a string, but I can't use string.remove(" ") , I would use: string.replace(" ", "") or: new_string = "" for i in string: if i != " ": new_string += I but I think there is a method like .remove() for list objects. Do you know any?

10th Jun 2018, 7:35 PM
Seb TheS
Seb TheS - avatar
2 Answers
+ 4
There are two methods:- "".join(string.split()) and string.replace(" ","")
10th Jun 2018, 7:42 PM
Akash Pal
Akash Pal - avatar
0
Akash Pal string.strip(substring)
7th Oct 2018, 4:36 PM
Seb TheS
Seb TheS - avatar