小册名称:Python合辑4-130个字符串操作示例
仅在 Python 中的双引号后拆分字符串
s = '"Canada", "Japan", "Germany", "Russia"'l = ['"{}"'.format(s) for s in s.split('"') if s not in ('', ', ')]for item in l: print(item)
s = '"Canada", "Japan", "Germany", "Russia"'
l = ['"{}"'.format(s) for s in s.split('"') if s not in ('', ', ')]
for item in l:
print(item)
Output:
"Canada""Japan""Germany""Russia"
"Canada"
"Japan"
"Germany"
"Russia"