How can I get around declaring an unused variable in a for loop?

后端 未结 10 1280
自闭症患者
自闭症患者 2020-11-27 16:03

If I have a list comprehension (for example) like this:

[\'\' for x in myList]

Effectively making a new list that has an empty string for e

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 16:46

    It turns out that using dummy* (starting word is dummy) as the variable name does the same trick as _. _ is a known standard and it would be better to use meaningful variable names. So you can use dummy, dummy1, dummy_anything. By using these variable names PyLint won't complain.

提交回复
热议问题