Import Time Time form, localtime, SLEEP
# timestamp, from 1 January 1970 0.0 seconds to now experienced the number of seconds
print (localitime (time ()) )
# Example: Create a parent class and subclass, the parent calculates two numbers recorded as the SUM, subclass print this the SUM DEF Joker (FUNC): DEF Warp (num1, num2): Print ( ' num1 + num2 = ' , + num1 num2) return FUNC (num1, num2) return Warp @joker DEF SUM (num1, num2): Print (num1, num2) Pass SUM ( 12 is , 14 )
Results: num1 num2 = + 26 is 12 is 14
# Example: listing formula A = (X for X in Range ( 100 ) IF X% 2 == 0 ) for I in Range ( 10 ): Print (Next (A)) # Formula # A = [X for X in Range ( 1000 ) IF X% 2 == 0 ] # advantages: fast calculation, because the disposable loading into memory, the amount of data is not suitable for the case of too large 10000 - 2000 - # disadvantages: memory for # generator #a = (the X- for the X- inRange ( 1000 ) IF X% 2 == 0 ) # advantages: saving memory space # drawbacks: slow calculation due to the generation
result:
#例:
def deco(func): def warp(H): print('joker') return func(H) return warp @deco def joker(name): print('hello %s'%name) joker('hena')
result:
joker hello hena