Day5 Main content:
1 Job Focus
2 Decorators
Single Layer Decorator
Multilayer Decorators
3 Modules
Built-in Modules
Custom Modules
Third-party modules
4 String Formatting
Http://www.cnblogs.com/wupeiqi/articles/5484747.html
1 Sequential Pass parameters
2 specifying name Parameters
3 keep the decimal point after several
4 If a placeholder is present, the write percent is printed with a %
5 generators and iterators
6 Other
Recursive
Bubble sort
Body Start:
Determine login
Judging permissions
Double-decked decorator
The explanation is from the bottom up.
The execution is from the top down
User_info ={}user_info['Is_login'] =trueuser_info['User_type'] = 2defCheck_login (func):defInner (*args,**Kwargs):ifUser_info.get ('Is_login', None): Ret= Func (*args,**Kwargs)returnretElse: Print('Please login') returnInnerdefCheck_admin (func):defInner (*args,**Kwargs):ifUser_info.get ('User_type', None) = = 2: Ret= Func (*args,**Kwargs)returnretElse: Print('Insufficient Authority') returnInner@check_login@check_admindefindex ():Print('Index') index ()
String formatting
%
Keep decimal digits
%c Asc code %o 8 in-system %x
When formatting, the placeholder % that appears in the string is required to print 2 percent percent to escape into a %
Percent escape
TP1 ='ASDSADSA%s 123123'%'Alex'Print(TP1) TP2='Asdsadsa%s 123123%d'% ('Alex', 14)Print(TP2) TP2='ASDSADSA%.2f 123123'% 1.66666Print(TP2) TP2='Asdsadsa% (PP). 2f 123123'% {'pp': 1.33232}Print(TP2) TP2='ASDSADSA%s%%123123'%'Alex'Print(TP2)
Common formatting:
Format:
Format supports conversion to 2 binary.
Common:
TPL ="-----{:* ^20s}======={:+d}======={:x}". Format ('Alex', 123,15)Print(TPL) TPL='12321321321 {:. 2%}'. Format (0.123123)Print(TPL) TPL='I am {},age {},{}'. Format ('Seven', 15,'Alex')Print(TPL) TPL='I am {},age {},{}'. Format (*['Seven', 15,'Alex'])Print(TPL) TPL='I am {0},age {1},{0}'. Format ('Seven', 15)Print(TPL) TPL='I am {name},age {age},{name}'. Format (**{'name':'Alex',' Age': 17})Print(TPL) TPL='I am {name},age {age},{name}'. Format (name ='Alex', age = 17)Print(TPL) TPL='I am {0[0]},age{0[1]}'. Format ([1,2,3],[1,3,4,5,56])Print(TPL) TPL='I am {: S},age is {:d}. Money {:. 2f}'. Format ('Seven', 15,123123.234)Print(TPL) TPL="{: b},{:o},{:d},{:x},{:x},{:%}". Format (15,16,15,18,5,15.33)Print(TPL) TPL='{0:b},{0:o},{0:b},{0:x},{0:x},{0:%}'. Format (15)Print(TPL)
Generator: Created using a function.
defmyrange (ARG): Start=0 whileTrue:ifStart >ARG:return yieldStart Start+ = 1ret= myrange (3) R= Ret.__next__()Print(r) R= Ret.__next__()Print(r) R= Ret.__next__()Print(r) R= Ret.__next__()Print(r)
test4
The day5 of Python