1.python 一切皆对象
掌握python的对象的管理方式
学习内容:
1、 python中一切皆对象
2、 type 、object 、 class之间的关系
3、 python常见的内置类型
1:python中一切皆对象
python中对象包含:类 函数 等
这里对象的概念与其他学科的概念是一样的,代码的设计更像是抽象映射我们的现实社会。所以对象的概念社会经济等其他学科会介绍的更具体。
python中对象的特点。
1)对象可以当参数使用,赋值给一个变量。
#函数
def sayhello(name):
print("hello",name)
my_func = sayhello
my_func("jenny")
----------------------
hello jenny
----------------------
#类
class PERSION():
def __init__(self,name):
print('hello',name)
myclass = PERSION
myclass("jenny")
------------------------
hello jenny
------------------------
def sayhello(name):
print("hello",name)
class PERSION():
def __init__(self,name):
print('hello',name)
list = []
list.append(sayhello)
list.append(PERSION)
index = 1
for item in list:
item("jenny%s"%index)
index+=1
--------------------------
hello jenny1
hello jenny2
-------------------------
def sayhello(name):
print("hello",name)
def voice():
print("say hello")
return sayhello
fun = voice()
fun("jenny")
----------------------------
say hello
hello jenny
提示:
fun = func() 与 fun = func 区别
一个是赋给返回值,一个是赋值自身
本文介绍了Python中一切皆对象的概念,探讨了type、object和class之间的关系,并通过实例演示了如何将对象作为参数使用、如何利用函数返回对象以及对象的赋值方式。

被折叠的 条评论
为什么被折叠?



