在列表列表中命名元素是一个很好的命名约定吗?

时间:2013-10-15 21:12:38

标签: python variables naming-conventions

我遇到过很多情况,例如

while(len(somelists) > 0):
    somelist = somelists.pop() # prob not the best example
    ...

在我阅读代码时,这经常让我感到困惑,因为我最终错过了那些代码。

由于我经常在许多语言中看到这种情况,我只是想知道这实际上是一个很好的命名约定吗?

1 个答案:

答案 0 :(得分:2)

s没问题,但list没有。尝试将变量命名为它们所代表的内容,而不是它们的类型。所以:

while(len(cars) > 0):
    car = cars.pop() 

当然,有些人设法完全避免s的问题。他们对汽车容器应用相同的建议,所以我们有:

while(len(dealership) > 0):
    car = dealership.pop()
相关问题