python3基础3

# 匿名函数:

bbb = lambda a, b: a + b
print(bbb(1,1))


# 函数

def add(a=None, b=None):
"""
接收两个整型参数,实现加法运算。
用法:
add(1, 2)
"""
print("run add...")
if a is None:
a = 2
if b is None:
b = 1

c = a + b
#print("result:", c)
return c

a = A().add() #初始化类的动作

cc = A.add(4, 8)
print("cc", cc)


# 类/方法
class MyClass: #

# 初始化方法
def __init__(self, a, b): # 爸爸
self.a = a #
self.b = b #

# 普通的方法
def sun(self):
print("工作了..")
self.money = 1000

def add(self): # 妈妈
self.sun()
print("买东西", self.money)
return self.a + self.b


myclass = MyClass(2, 3)
c = myclass.add()
print("c-->", c)

print("---------------------------------")

global HELLO #全局

class A:
dianchi = "电池"

@classmethod
def hello():
HELLO = "asdfasdf"
print("hello",HELLO)


A.hello()


print("---------------------------------")

class A(object):

def __init__(self, a, b): 
self.a = a 
self.b = b

def add(self):
return self.a + self.b

def car(self):
print("装上"+ self.dianchi)
print("跑了")

class B(A):

dianchi = "5号电池"

def __init__(self, a, b , c):
A.__init__(self, a, b)
self.c = c

class C(B):
pass

b = A(1, 2)
b.car()

 

 

posted @ 2019-12-15 08:35  Harry_666  阅读(253)  评论(0编辑  收藏  举报