Python series: Understand functions, classes, methods, attributes, and parameters

=============Function example=============

def Function(a,b)

        c=a*b

        d=a+b

        return c, d

==========Class example==================

class Object:
    def __init__(self, attribute_a, attribute_b, attribute_c):
        self.attribute_ago = attribute_a
        self.attribute_bgo = attribute_b
        self.attribute_cgo = attribute_c

    def methodwalk(self):
        self.methodwalk = self.attribute_ago + self.attribute_bgo + self.attribute_cgo
        return self.methodwalk

    def methodfly(self):
        self.methodfly = self.attribute_ago * self.attribute_bgo * self.attribute_cgo
        return self.methodfly

parameter_a = 1
parameter_b = 2
parameter_c = 3

obj1 = Object(parameter_a, parameter_b, parameter_c)

walk1 = obj1.methodwalk()
fly1 = obj1.methodfly()

print("Walk:", walk1)
print("Fly:", fly1)


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值