“Python Trim Whitespace od końca sznurka” Kod odpowiedzi

Przycinanie przestrzeni w Pythonie sznurkowym

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

Python Usuń Whitespace od początku sznurka

'     hello world!    '.strip()
'hello world!'


'     hello world!    '.lstrip()
'hello world!    '

'     hello world!    '.rstrip()
'    hello world!'
Breakable Buffalo

Python Trim Whitespace od końca sznurka

>>> "    xyz     ".rstrip()
'    xyz'
Embarrassed Earthworm

String Python Usuń białe znak

' sss d ssd s'.replace(" ", "")
# output: 'sssdssds' 
David Diamant

Python Strip Whitespace


s1 = '  abc  '

print(f'String =\'{s1}\'')

print(f'After Removing Leading Whitespaces String =\'{s1.lstrip()}\'')

print(f'After Removing Trailing Whitespaces String =\'{s1.rstrip()}\'')

print(f'After Trimming Whitespaces String =\'{s1.strip()}\'')
Awful Ape

Odpowiedzi podobne do “Python Trim Whitespace od końca sznurka”

Pytania podobne do “Python Trim Whitespace od końca sznurka”

Więcej pokrewnych odpowiedzi na “Python Trim Whitespace od końca sznurka” w Python

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

Przeglądaj inne języki kodu