python返回对象_函数返回一个对象-python

时间:2025-02-21 08:36:16

这个疑问的起源在于:

a=open(“”,”w”)

()

为什么a会有一个方法(.close),因为open是一个函数

经过学习,了解到函数可以返回一个对象 .

print("测试函数返回一个对象")

def nameandage(x,y):

class man:

def __init__(self,name,age):

=name

= age

def theage(self):

print(,"的年龄为",)

def thename(self):

print("这个人的名字叫做",)

people=man(x,y)

return people

cw=nameandage("蔡文",32)

kcj=nameandage("寇长江",33)

()

()

()

()

print("下面看一下type:")

print(type(cw))

print(type(open))

print(type(nameandage))#注意,看type不需要()

print(type())

print(type())

这部分代码在类的学习二种有记录,因为比较重要,故单独列出