溫馨提示×

strip在python中怎么使用

小億
94
2024-02-28 09:33:11
欄目: 編程語言

在Python中,strip()函數用于去除字符串兩端的指定字符(默認為空格)或空白符??梢允褂靡韵路绞絹硎褂?code>strip()函數:

  1. 使用默認的空格字符去除兩端空格:
s = "  hello world  "
print(s.strip())  # Output: "hello world"
  1. 指定要去除的字符:
s = "!!!hello world!!!"
print(s.strip("!"))  # Output: "hello world"
  1. 去除指定字符集合:
s = "!!!hello world!!!"
print(s.strip("!d"))  # Output: "hello worl"

需要注意的是,strip()函數會返回一個新的字符串,原始字符串不會被修改。

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