What does _ mean in Python
2018-10-26 本文已影响0人
lixiaoquan
If you come from C/C++, you may be confused about the standalone _ in Python code. It actually acts as a temp variable which can be used later. That's it.
But most of time, it is used because we don't care its value later. For example, there is a function which returns two values, and we only are interested in the second return value. At the mean time, we don't want to create a variable because naming a variable is boring and may causes 'Not used variable' warning.
def func():
return 1, 2
_, x = func()