The python interpreter stores the last expression value to the special variable called
_.>>> 10 10 >>> _ 10 >>> _ * 3 30The underscore
_is also used for ignoring the specific values. If you don’t need the specific values or the values are not used, just assign the values to underscore.Ignore a value when unpacking
x, _, y = (1, 2, 3) >>> x 1 >>> y 3Ignore the index
for _ in range(10): do_something()
No comments:
Post a Comment