【发布时间】:2021-04-27 05:01:45
【问题描述】:
我正在 Python 上构建一个 if 语句,当正则表达式的 match 函数发现巧合时打印一些东西。我想知道为什么当我的语句的条件不是布尔值时 if 语句有效(我认为是这样)。
import re
coincidence = re.match(r'\w{3}', 'abc')
if coincidence:
print('There\'s a match')
产生:
"There's a match"
为什么会起作用?
【问题讨论】:
-
没有“if 循环”。
if不循环。 -
你是对的。我会改的。
标签: python python-3.x regex if-statement