+ 4

Is there any other method to do it?

I have made a simple program to remove spaces from a string in python. But I want to know is there any other method to do it. Please let me know is there any other method to do it. https://code.sololearn.com/ca8domPwiGm1/?ref=app

21st Oct 2020, 12:38 PM
Aditya
Aditya - avatar
3 Respuestas
+ 8
st=input() st=st.replace(" ","") print (st)
21st Oct 2020, 12:48 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 3
Yup but without using any built in methods str="" for j in i: if j!=" ": str+=j print(str)
21st Oct 2020, 12:52 PM
Abhay
Abhay - avatar
+ 2
Yes there are 👍 1- with replace method: txt = input( clean_txt = i.replace(" ", "") 2- without built in method: txt = str(input()) for i in range(len(txt)): char = txt[i] if char != " ": clean_txt += char This is what I know may be there is a better way to do it🤷‍♂️.
21st Oct 2020, 12:52 PM
‎يوسف سعد‎
‎يوسف سعد‎ - avatar