“Hapus spasi dari string python” Kode Jawaban

cara menghapus semua spasi dari string di 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

Hapus spasi dari daftar ular python

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

Pemangkasan Ruang Dalam Python String

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

python convert lepaskan spasi dari awal string

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

Hapus spasi dalam python string

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

Hapus spasi dari string python

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

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

Jawaban yang mirip dengan “Hapus spasi dari string python”

Pertanyaan yang mirip dengan “Hapus spasi dari string python”

Lebih banyak jawaban terkait untuk “Hapus spasi dari string python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya