1.python 一切皆对象

本文介绍了Python中一切皆对象的概念,探讨了type、object和class之间的关系,并通过实例演示了如何将对象作为参数使用、如何利用函数返回对象以及对象的赋值方式。

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 区别
一个是赋给返回值,一个是赋值自身

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值