What is the purpose of the single underscore “_” variable in Python?

后端 未结 5 1637
后悔当初
后悔当初 2020-11-21 04:04

What is the meaning of _ after for in this code?

if tbh.bag:
   n = 0
   for _ in tbh.bag.atom_set():
      n += 1
5条回答
  •  既然无缘
    2020-11-21 05:06

    It's just a variable name, and it's conventional in python to use _ for throwaway variables. It just indicates that the loop variable isn't actually used.

提交回复
热议问题