字符串中的前导空格就是出现在字符串中第一个非空格字符前的空格,我们使用方法lstrip()可以将它从字符串中移除

a='   Ayushi '.lstrip()
print(a)

#Ayushi 

可以看到,该字符串既有前导字符,也有后缀字符,调用lstrip()去除了前导空格,如果我们想去除后缀空格,就用rstrip()方法

a='   Ayushi '.rstrip()
print(a)

#   Ayushi

 

相关文章:

  • 2022-03-10
  • 2022-12-23
  • 2022-01-09
  • 2022-02-05
  • 2021-08-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2022-01-07
  • 2023-04-03
相关资源
相似解决方案