python3 base 3

# Anonymous function:

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


# Function

the Add DEF (A = None, B = None):
"" "
received two integer parameters, and the adder.
Usage:
the Add (. 1, 2)
" ""
Print ( "RUN the Add ...")
IF IS A none:
A = 2
IF IS none B:
B =. 1

C = A + B
#Print ( "Result:", C)
return C

a = A (). Action add () # class initialization

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


# Class / method
class MyClass: # home

# Initialize method
def __init __ (self, a, b): # father
self.a = a # money
self.b = b # money

# Conventional method
DEF Sun (Self):
Print ( "work ..")
self.money = 1000

def add (self): # Mom
self.sun ()
Print ( "shopping", self.money)
return self.a + self.b


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

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

Global global HELLO #

A class:
Dianchi = "Battery"

@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 batteries"

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

class C(B):
pass

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

 

Guess you like

Origin www.cnblogs.com/hy546880109/p/12041861.html