The structure statement of Python learning

Source: Internet
Author: User

A loop statement:

1.1 for X in Rang (n): #rang (n) generates a sequence of left closed right open intervals

1.2 While x condition N:

Two conditional statements:

An IF condition expression:

Elif expression:

Elif expression:

...

Else

Three Break Continu

Four: function:

4.1 Definition: def func (parameter list):

    if not isinstance(x, (int, float)):#参数检查相当于断言

      raise TypeError(‘bad operand type‘)

Return argument list # "when more than one return is actually returned a tuple (with the remaining parentheses), does not show return actually went back to none"

4.2 References: from filename.py import func_name

4.3 null function: Def NOP ():

Pass #占位语句, error-proof also for later expansion convenience.

4.4 Parameters of the function: Default parameter (x,y=2), variable parameter (equivalent to tuple, * tuple or list), keyword argument (dict class * *). The name keyword argument (*,x,y):* followed by the keyword argument.

4.5 Recursive function: Clear structure (recursive can be written as a looping structure), but to prevent stack overflow (to be optimized with tail recursion)

The structure statement of Python learning

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.