請問“else”那里縮進(jìn)與不縮進(jìn)有什么區(qū)別?
>>> L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> S = set([1, 3, 5, 7, 9])
>>> for item in L:
...? ? ?if item in S:
...? ? ? ? ?S.remove(item)
... else:
...? ? ?S.add(item)
...? ? ?print(S)
...
{10}
>>> L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> S = set([1, 3, 5, 7, 9])
>>> for item in L:
...? ? ?if item in S:
...? ? ? ? ?S.remove(item)
... else:
...? ? ?S.add(item)
...? ? ?print(S)
...
{10}
2020-09-26
舉報(bào)
2020-09-27
和if齊平就還在for循環(huán)里,不縮進(jìn)就在for循環(huán)外了。