小编Ken*_*ers的帖子

引用方法中的属性

在类中的方法中引用具有新变量名的属性是不好的做法吗?例如:

class Stuff:
    def __init__(self, a):
        self.a = a

    def some_method(self):
        a = self.a
        # Do some stuff with a
Run Code Online (Sandbox Code Playgroud)

我已经在其他人的代码中看到了这一点,我已经养成了自己的习惯,尤其是长变量名.a当我这样做时,它似乎是一个副本,如果a非常大,可能会出现问题.我是不是应该坚持呼吁self.a里面some_method?python垃圾会asome_method调用后收集创建的吗?

python attributes class python-2.7 python-3.x

0
推荐指数
1
解决办法
46
查看次数

楼层划分操作员的结果存在差异

我发现今天的楼层划分有些奇怪:

>>> 10.1/1.01
10.0
>>> 10.1//1.01
9.0

>>> 2688937/268893.7
10.0
>>> 2688937//268893.7
9.0

>>> 6.6/3.3
2.0
>>> 6.6//3.3
2.0
Run Code Online (Sandbox Code Playgroud)

我认为这是由于浮点错误引起的,但我想知道是否还有其他一些原因会使10.0下降到9.0。

python python-3.x

0
推荐指数
1
解决办法
38
查看次数

标签 统计

python ×2

python-3.x ×2

attributes ×1

class ×1

python-2.7 ×1