請問“else”那里縮進與不縮進有什么區別?
>>> 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
舉報
2020-09-27
和if齊平就還在for循環里,不縮進就在for循環外了。