目前要在字符串周围添加单引号,我想出的最佳解决方案是制作一个小包装函数。
def foo(s1):
return "'" + s1 + "'"
有没有更简单的 pythonic 方式来做到这一点?
最佳答案
这是另一个(可能更像 pythonic)选项,使用 format strings :
def foo(s1):
return "'{}'".format(s1)
关于Python 2.X 在字符串周围添加单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22952543/