共計 412 個字符,預計需要花費 2 分鐘才能閱讀完成。
Python 中可以使用以下方法去掉字符串中的引號:
- 使用
strip()方法去掉字符串兩邊的引號:
string = '"Hello, World!"'
new_string = string.strip('"')
print(new_string) # Output: Hello, World!
- 使用切片去掉字符串的引號:
string = '"Hello, World!"'
new_string = string[1:-1]
print(new_string) # Output: Hello, World!
- 使用
replace()方法將引號替換為空字符串:
string = '"Hello, World!"'
new_string = string.replace('"','')
print(new_string) # Output: Hello, World!
請注意,以上方法只能去掉字符串兩邊的引號,如果字符串中間還包含引號,需要根據具體情況進行處理。
丸趣 TV 網 – 提供最優質的資源集合!
正文完