lstrip()
根据参数(指定要移除的字符集的字符串)从左侧移除字符。
lstrip()
的语法是
string.lstrip([chars])
lstrip() 参数
- chars(可选)- 指定要移除的字符集的字符串。
如果未提供 chars 参数,则会从字符串中移除所有前导空格。
lstrip() 的返回值
lstrip()
返回字符串的副本,其中移除了前导字符。
在 chars 参数中,所有字符组合都从字符串的左侧移除,直到第一次不匹配。
示例:lstrip() 的工作原理
random_string = ' this is good '
# Leading whitepsace are removed
print(random_string.lstrip())
# Argument doesn't contain space
# No characters are removed.
print(random_string.lstrip('sti'))
print(random_string.lstrip('s ti'))
website = 'https://programiz.com.cn/'
print(website.lstrip('htps:/.'))
输出
this is good this is good his is good www.programiz.com/
另请阅读