且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中删除字符串中的引号

更新时间:2023-12-03 19:16:34

仅在字符串方法.replace()始终出现时使用,否则使用.strip()如果仅在开始和/或结束时出现:

Just use string methods .replace() if they occur throughout, or .strip() if they only occur at the start and/or finish:

a = '"sajdkasjdsak" "asdasdasds"' 

a = a.replace('"', '')
'sajdkasjdsak asdasdasds'

# or, if they only occur at start and end...
a = a.strip('\"')
'sajdkasjdsak" "asdasdasds'

# or, if they only occur at start...
a = a.lstrip('\"')

# or, if they only occur at end...
a = a.rstrip('\"')