Day 19 sequentially decorative generator expression yield

# A superimposed load multiple decorators, run the analysis (understanding ***) 

DEF deco1 (func1): # func1 = wrapper2 memory address
DEF wrapper1 (* args, ** kwargs):
Print ( 'running == => deco1.wrapper1 ')
RES1 = func1 (* args, ** kwargs)
return RES1
return wrapper1

DEF deco2 (func2): # = func2 wrapper3 memory address
DEF wrapper2 (* args, ** kwargs):
Print (' is run ===> deco2.wrapper2 ')
RES2 = func2 (* args, ** kwargs)
return RES2
return wrapper2

DEF deco3 (X):
DEF outter3 (func3): = # func3 the memory address index function decorative objects
def wrapper3 (* args, ** kwargs):
Print ( 'running ===> deco3.outter3.wrapper3')
RES3 = func3 (* args, ** kwargs)
return RES3
wrapper3 return
return outter3


# loaded from the bottom up (Learn)
@ # deco1 index = deco1 (wrapper2 memory address) ===> index = wrapper1 memory address
@ deco2 # index = deco2 (wrapper3 memory address) == => index = wrapper2 memory address
@ deco3 (111) # ===> @ outter3 ===> index = outter3 (index) ===> index = wrapper3 memory address
DEF index (X, Y):
Print ( 'index from% S:% S'% (X, Y))

# perform top-down order, i.e. wraper1- "wrapper2-" wrapper3
index (1,2) # wrapper1 (1,2)




# X = yield Return Value

# a:
# DEF Dog (name):
# Print ( '% s Columbia Road ready to eat it ...'% name)
# the while True:
# # X got the yield received value
# x = yield # x = 'meat bun'
# Print ( '% s eat Columbia Road% s'% (name, X))
#
#
# Dog G = ( 'Alex')
# g.send (None) equivalent to # Next (G)
#
# g.send ([ 'a bone', 'AAA'])
# # g.send ( 'meat bun')
# # g.send ( 'together swill')
# G # .close ()
# # g.send ( '1111') can not pass the value after closing #


# two:
DEF Dog (name):
food_list = []
Print ( '% s Columbia Road ready to eat it ...'% name )
the while True:
# X got the yield value of the received
x = yield food_list # x = 'meat buns'
print ( '% s eat Columbia Road% s'% (name, x ))
food_list.append (x) # [ 'a bone', 'meat bun']
#
# Dog G = ( "Alex")
# RES = g.send (None) # Next (G)
# Print (RES)
#
# res = g.send ( 'a bone')
# Print (RES)
#
# res = g.send ( 'meat bun')
# Print (RES)
# # g.send ( 'together swill')




DEF FUNC () :
Print ( 'Start .....')
X = X = the yield # 1111 'XXXXX'
Print ( 'ha aha')
Print ( 'ha aha')
Print ( 'ha aha')
Print ( 'ha aha')
the yield 22222

G = FUNC ()
RES = Next (G)
Print (RES)

RES = g.send ( 'XXXXX')
Print (RES)

Ternary expressions with # 
# Syntax: else if condition value condition is satisfied when the condition is not satisfied to return to return a value
X =. 1
Y = 2

# RES = X if X> Y Y else
# Print (RES)


RES = 111111 IF 'Egon' == 'Egon' the else 2222222222
Print (RES)



# usage
DEF FUNC ():
# IF. 1>. 3:
# = X. 1
# the else:
#. 3 X =

X = IF. 1. 1>. 3 the else. 3


# 1, formula list 
L = [ 'alex_dsb', 'lxx_dsb', 'wxx_dsb', "xxq_dsb", 'Egon']
# new_l = []
# for L in name:
# name.endswith IF ( 'DSB') :
# new_l.append (name)


# new_l = [L IF name in name for name.endswith ( 'DSB')]
# new_l = [name in name for L]

# Print (new_l)

# all lowercase letters become full uppercase
# new_l = [name.upper () for name in L]
# Print (new_l)

# remove all name suffix _dsb
# new_l = [name.replace ( '_ DSB', '') for name in L]
# Print (new_l)

# 2, dictionary formula
# Keys = [ 'name', 'Age', 'Gender']
# DIC = {Key: None for Key in Keys}
# Print (DIC)

# items = [( 'name ',' egon '), ( ' age ', 18), ('gender','male')]
# res={k:v for k,v in items if k != 'gender'}
# Print (RES)

#. 3, the collection formula
# Keys = [ 'name', 'Age', 'Gender']
# setl = {Key for Key in Keys}
# Print (setl, type (setl))


#. 4, generator expression
# = G (I for I in Range (10) IF I>. 3)
#! ! ! ! ! ! ! ! ! ! ! Emphasize! ! ! ! ! ! ! ! ! ! ! ! ! ! !
# Now g interior of a value not

# Print (g, type (g))

# Print (g)
# Print (Next (g))
# Print (Next (g))
# Print (Next (g))
# Print ( Next (G))
# Print (Next (G))
# Print (Next (G))
# Print (Next (G))


with Open ( 'notes .txt', mode = 'rt' , encoding = 'utf-8 ') AS F:
# a way:
# RES = 0
# Line for in F:





# Print (RES)

# Three ways: the most efficient
# RES = SUM ((len (Line) for Line in F))
# above-can be abbreviated as follows
RES = SUM (len (Line) for Line in F)
Print (RES )




Guess you like

Origin www.cnblogs.com/AaronY/p/12571836.html