The day5 of Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.