“Usuń przestrzeń z Python String” Kod odpowiedzi

Jak usunąć wszystkie przestrzenie ze sznurka w Pythonie

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

Przycinanie przestrzeni w Pythonie sznurkowym

a = "      yo!      "
b = a.strip() # this will remove the white spaces that are leading and trailing
Super Stoat

Usuń po i przed przestrzenią Python

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

Python Przekształć Usuń przestrzenie od początku sznurka

## Remove the Starting Spaces in Python
 
string1="    This is Test String to strip leading space"
print (string1.lstrip())
Embarrassed Earthworm

Usuń spacje w Pythonie strunowym

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

Usuń przestrzeń z Python String

sentence.replace(" ", "")
Faithful Fish

Odpowiedzi podobne do “Usuń przestrzeń z Python String”

Pytania podobne do “Usuń przestrzeń z Python String”

Więcej pokrewnych odpowiedzi na “Usuń przestrzeń z Python String” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu