2024-04-26 23:56:15 发布
网友
Stackoverflow is best
我想做:
"""Stackoverflow is best"""
如何用regex插入特殊字符,或者有其他方法吗?你知道吗
试试这个
str1 = '"""Stackoverflow is best"""' # you can interchange the double and single quotes in python print str1
使用单引号:
foo = '"""Stackoverflow is best"""'
或者可以使用转义字符:
foo = "\"\"\"Stackoverflow is best \"\"\""
创建foo不需要regex。你知道吗
我想你想要这样的东西
>>> foo = 'Stackoverflow is best ' >>> import re >>> foo = re.sub(r'^\s*|\s*$', r'"""', foo) >>> foo '"""Stackoverflow is best"""'
试试这个
使用单引号:
或者可以使用转义字符:
创建foo不需要regex。你知道吗
我想你想要这样的东西
相关问题 更多 >
编程相关推荐