我只是好奇为什么我见过的大多数使用正则表达式时使用 re.verbose 的示例都使用 '''?
我找到的一个例子如下所示
address = re.compile(
''' #THIS
[\w\d.+-]+ # username
@
([\w\d.]+\.)+ # domain name prefix
(com|org|edu) # we should support more top-level domains
''', #AND THIS
re.UNICODE | re.VERBOSE)
最佳答案
使用'''
允许字符串跨越多行,因此它们可以分解re的每个部分,而不是有一长行。
这样做是为了代码可读性,而不是功能。
请参阅Python Tutorial strings section有关跨多行字符串的更多信息。
关于python - 在 python 中使用 re.verbose 时使用三个开闭引号的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6012806/