Python3_04. Loops & Functions

Source: Internet
Author: User

1. Cycle & Condition Control

Note:

        • Each condition is followed by a colon (:), which represents the next block of statements to be executed after the condition is met.

        • Using indentation to divide a statement block, a statement with the same indent number together makes up a block of statements.

        • The break statement can jump out of a for and while loop body.

        • The continue statement is used to tell Python to skip the remaining statements in the current loop block and proceed to the next round of loops.

        • Pass is an empty statement in order to maintain the integrity of the program structure. Pass does not do anything, generally used as a placeholder statement.

Cycling Tips:

        • When looping through a dictionary, keywords and corresponding values can be interpreted simultaneously using the items () method

        • when looping through a sequence, the index position and the corresponding value can be used Enumerate () functions are also

        • To loop two or more sequences at the same time, you can use zip () Overall Packaging

        • If a reverse loop sequence is required, the sequence is positioned first and then called reversed () function

Operator Describe
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equals, compares objects for equality
!= Not equal to

2. Functions

Attention:

      • The function code block begins with a def keyword followed by the function identifier name and parentheses ().

      • Any incoming parameters and arguments must be placed in the middle of the parentheses, and the parentheses can be used to define the parameters.

      • The first line of the function statement can optionally use the document string-for storing the function description.

      • The function contents begin with a colon and are indented.

      • return [expression] ends the function, optionally returning a value to the caller. Return without an expression is equivalent to returning None.

Function call:

def function (str): ' Print any incoming string ' (function description) print (str) return ' OK ' function (' I want to invoke this custom function ') (function call) function (' Call again ')




This article is from the "unplug the Operational Space" blog, please be sure to keep this source http://zhangdj.blog.51cto.com/9210512/1881436

Python3_04. Loops & Functions

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.