【发布时间】:2018-03-08 01:32:30
【问题描述】:
在我的程序中,我正在阅读另一个 python 程序,我想找到一些特殊的 python 关键字。当我找到它们时,我想在找到的关键字之前和之后打印一些代码。
这是我的代码:
if line.find("def") == True or line.find("if") == True or line.find("elif") == True:
print("<span style=\"color: orange;\">",True,"</span>","<br>", end="")
在打印语句“True”中,我希望它是程序读取的值。
我不知道我是否正确执行“或”语句,但输出不起作用。 我没有收到任何错误或任何东西。我希望我的输出是上面的 HTML 代码,然后是找到的关键字和结束的 HTML 代码。
示例输出:
<span style=\"color: orange;\">if</span>
<span style=\"color: orange;\">def</span>
<span style=\"color: orange;\">elif</span>
【问题讨论】:
-
知道了!我希望这现在有意义。
标签: python file if-statement printing find