溫馨提示×

python怎么去除字符串前后空格

小億
106
2023-11-29 13:07:19
欄目: 編程語言

在Python中,可以使用字符串的strip()方法來去除字符串前后的空格。示例如下:

s = "  hello world  "
s = s.strip()
print(s)  # 輸出:hello world

另外,如果只想去除字符串前面的空格,可以使用lstrip()方法;如果只想去除字符串后面的空格,可以使用rstrip()方法。示例如下:

s = "  hello world  "
s = s.lstrip()
print(s)  # 輸出:hello world

s = "  hello world  "
s = s.rstrip()
print(s)  # 輸出:  hello world

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女