+ 5

Pls how do i remove white space between two words in python

Python

1st Nov 2019, 9:57 PM
Peter Paulinus Polycarp
Peter Paulinus Polycarp - avatar
13 Respuestas
2nd Nov 2019, 8:16 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
Peter Paulinus Polycarp , I suggest using the str.strip(), str.replace(), and str.split() functions. Here are my examples: To remove leading and ending spaces, use str.strip. words = “ yes please “ words.strip() To remove all spaces, use str.replace() words = “these are some words” words.replace(“ “, “”) To remove duplicated spaces, use str.split(). words = “. hello words. “ “ “.join(words.split()) Hope this helps!
1st Nov 2019, 10:04 PM
Brock Miller
Brock Miller - avatar
+ 3
Hello mystring.replace(' ', '') Will remove all spaces! Hopes this helps!
1st Nov 2019, 10:08 PM
Loïc Mahé
Loïc Mahé - avatar
+ 2
Thanks@brock Miller
1st Nov 2019, 10:14 PM
Peter Paulinus Polycarp
Peter Paulinus Polycarp - avatar
+ 2
Of course!
1st Nov 2019, 10:15 PM
Brock Miller
Brock Miller - avatar
+ 2
split() and join() functions could be used.
3rd Nov 2019, 4:15 AM
Sonic
Sonic - avatar
10th Nov 2019, 6:06 PM
Isaac Duah [Active!]
Isaac Duah [Active!] - avatar
+ 1
1st Nov 2019, 10:13 PM
Peter Paulinus Polycarp
Peter Paulinus Polycarp - avatar
2nd Nov 2019, 4:40 PM
NerdY
- 1
Hi
3rd Nov 2019, 12:55 PM
Noman Ali
Noman Ali - avatar
3rd Nov 2019, 2:19 PM
Andrew Johnson
Andrew Johnson - avatar