Home > Backend Development > Python Tutorial > How to remove the last space in Python

How to remove the last space in Python

(*-*)浩
Release: 2019-07-03 11:02:26
Original
11628 people have browsed it

strip() function removes spaces\n\r\tUsage of function

How to remove the last space in Python

strip removes spaces on both sides at the same time(recommended learning: Python video tutorial)

lstrip Remove the spaces on the left

rstrip Remove the spaces on the right

Specific examples are as follows:

>>>a=" hello world!!  "
>>>a.lstrip() 'hello world!! '
>>>a.rstrip() ' hello world!!'
>>>a.strip() 'hello world!!'
Copy after login

Statement: s is a string, rm is the character sequence to be deleted

s.strip(rm) deletes the s string The characters in the rm deletion sequence at the beginning and end of the s string

s.lstrip(rm) Delete the characters in the rm deletion sequence at the beginning and end of the s string

s.rstrip(rm) Delete the characters in the rm deletion sequence at the end of the s string

Note:

When rm is empty, whitespace characters (including '\n') are deleted by default , '\r', '\t', ' ')

>>> a = ' hello world!!'
>>> a.strip()
'hello world!!'
>>> a='\t\thello world!!'
'hello world!!'
>>> a = 'hello world!!\r\n'
>>> a.strip()
'hello world!!'
Copy after login

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to remove the last space in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template