想象一下,我有一个函数可以返回循环中url的内容.所以我有:
while True:
content = ContentFunc()
Run Code Online (Sandbox Code Playgroud)
当该行在我的Python脚本中运行时,我如何理解content返回是否content与上一次循环迭代中返回的内容完全重复?
我如何理解"测试"一词重复10次?
谢谢
您可以检查这样的精确重复,假设content只是一个str而不是自定义对象:
prev_content = ""
while True:
content = ContentFunc()
if content == prev_content:
print("Same as last time")
prev_content = content
Run Code Online (Sandbox Code Playgroud)
您只需将上一次迭代的结果存储在变量(prev_content)中,并将其与当前迭代获得的结果进行比较.
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |