玉火叢生 发表于 2017-4-14 19:31:08

感觉静态方法没什么X用啊{:10_247:}

太阳花田 发表于 2017-4-24 15:08:16

看得想哭{:10_266:}感觉在学一个月再来看吧学到类这里就被各种 类 实例化 类对象 实例化对象 绑定……名词绕到头晕了

Santi 发表于 2017-5-8 23:04:07

我能说我看不懂么 ?哈哈 没看懂

DuRongqiang 发表于 2017-5-10 22:09:16

学习了,开心

遗忘= 发表于 2017-5-26 21:51:27

一脸蒙”逼“{:10_266:}

wyh2006 发表于 2017-6-2 21:42:56

慢慢消化

luohaihaha 发表于 2017-10-19 20:34:03

1,静态方法或熟悉;类方法;   普通方法。 可总结成一句话,大家看看说的对不

在同一个地方和同一个美女XXOO; 在不同的地方和同一个美女XXOO;在不同的地方和不同的美女XXOO

outmanlol 发表于 2017-12-4 21:37:49

第一次看得这么一脸懵逼,可能是我的打开方式有问题{:10_269:}

六神 发表于 2018-1-3 15:23:55

看不懂是什么水平

outmanlol 发表于 2018-1-3 22:24:47

一脸懵逼的来,一脸懵逼的离开。。。{:10_266:}

raimond 发表于 2018-1-21 23:24:18

{:5_91:}

Fire_Lang 发表于 2018-1-24 15:07:18

感觉还可以!!!和Java相比,Java更好点,Python不严谨!!!抽象方法的实现在不同版本中也不一样,兼容性很差!!!{:10_266:}{:10_266:}{:10_266:}

AdaHao 发表于 2018-1-27 14:47:11

1.Python将所有类的方法都绑定到类的对象的任何实例中

dahua123333 发表于 2018-4-1 14:13:03

小甲鱼,英文直接翻译不好吧,看着头大,还不看英文呢

傲娇团团 发表于 2018-5-16 10:58:10

1)静态方法
as we can see from usage of staticmethod, we don't have any access to what the class is- it's basically just a function, called syntactically like a method, but without access to the object and it's internals (fields and another methods), while classmethod does.(静态方法内部与类完全无关)
class Pizza(object):
    @staticmethod
    def mix_ingredients(x, y):
      return x + y

    def cook(self):
      return self.mix_ingredients(self.cheese, self.vegetables)

>>> Pizza().cook is Pizza().cook   #为每一个新创建的对象绑定了方法。绑定的方法同样是对象。
False
>>> Pizza().mix_ingredients is Pizza().mix_ingredients#静态的方法不依赖于对象
True
>>> Pizza().mix_ingredients is Pizza.mix_ingredients
True
>>> Pizza()
<__main__.Pizza object at 0x10314b410>
>>> Pizza()
<__main__.Pizza object at 0x10314b510>
>>>
2)类方法
关于类方法的使用场景
Class methods are for when you need to have methods that aren't specific to any particular instance, but still involve the class in some way. The most interesting thing about them is that they can be overridden by subclasses, something that's simply not possible in Java's static methods or Python's module-level functions.
Though classmethod and staticmethod are quite similar, there's a slight difference in usage for both entities: classmethod must have a reference to a class object as the first parameter, whereas staticmethod can have no parameters at all.

参考:
https://stackoverflow.com/questions/12179271/meaning-of-classmethod-and-staticmethod-for-beginner/12179752

金刚 发表于 2018-6-9 09:55:31

梦想绘制者 发表于 2016-11-26 11:16
cls 是个啥?感觉跟self有的一拼

class

magineer 发表于 2018-6-27 15:23:53

看不懂。。有些语句写得很悔涩。。还有很多代码没缩进。。表示 这很不是不小甲鱼的风格

小新新么么哒 发表于 2018-8-2 18:12:51

这个很全面

学学看看 发表于 2018-11-26 17:58:19

yanyanlin1994 发表于 2018-11-27 16:24:11

看的头都大了
页: 1 [2] 3 4
查看完整版本: 如何使用静态方法、类方法或者抽象方法(转)