我有一个我什至不知道如何搜索的问题。以这个简单的类为例:
class Student(object):
def _init_(self):
self.id = 0
def inc(self):
self.id += 1
std_gen = Student
什么是std_gen
?我试过了:
print(type(std_gen))
我得到了这个:
<class 'type'>
我需要找到它的类型并将其添加到文档字符串中。我甚至无法找到something
该回报True
与isinstance(std_gen, something)
编辑:我发现了isinstance(std_gen, type)
回报,True
但在文档字符串中几乎没有任何意义。这意味着什么?
学生班是“类型”类型的实例。有关更多信息,请参见元类。所以type(Student)是'type'。所以
s = Student()
std_gen = Student
type(s) // <class 'Student'>
type(std_gen) // <class 'type'>
总而言之,s是Student的实例,Student是类型的实例,stu_gen只是Student的别名。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句