“Entfernen Sie den leeren Speicherplatz von der Schnurpython” Code-Antworten

So entfernen Sie alle Räume von einer Schnur in Python

string = "Hello, world! Some more text here..." # Just a string
string.replace(" ", "") # Replaces all instances of " " (spaces)with "" (nothing)

# string is now "Hello,World!Somemoretexthere..."
# I hope I helped you! ;)
The Angriest Crusader

Entfernen Sie leere Leerzeichen von einer Liste Python

for i in range(0,(len(list))):
        x = str(list[i]).strip(' ')
        list[i] = x
Vihaking

Entfernen Sie nach und vor dem Weltraum -Python

st = " a "
strip(st)
#Output : "a"
Inquisitive Ibis

Entfernen Sie Leerzeichen in der Schnurpython

words = "   test     words    "

# Remove end spaces
def remove_end_spaces(string):
    return "".join(string.rstrip())

# Remove first and  end spaces
def remove_first_end_spaces(string):
    return "".join(string.rstrip().lstrip())

# Remove all spaces
def remove_all_spaces(string):
    return "".join(string.split())

# Remove all extra spaces
def remove_all_extra_spaces(string):
    return " ".join(string.split())

# Show results
print(f'"{words}"')
print(f'"{remove_end_spaces(words)}"')
print(f'"{remove_first_end_spaces(words)}"')
print(f'"{remove_all_spaces(words)}"')
print(f'"{remove_all_extra_spaces(words)}"')
Everybody Poops

Entfernen Sie Leerzeichen von der Schnurpython

s = '  Hello   World     From  Pankaj  \t\n\r\t  Hi       There        '

>>> s.replace(" ", "")
'HelloWorldFromPankaj\t\n\r\tHiThere'
Envious Emu

Entfernen Sie den leeren Speicherplatz von der Schnurpython

string = "Welcome to Python"
new_str = "".join(string.split(" "))
print(new_str) # "WelcometoPython"
Cap'n Joseph Burntbeard

Ähnliche Antworten wie “Entfernen Sie den leeren Speicherplatz von der Schnurpython”

Fragen ähnlich wie “Entfernen Sie den leeren Speicherplatz von der Schnurpython”

Weitere verwandte Antworten zu “Entfernen Sie den leeren Speicherplatz von der Schnurpython” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen