Built-in functions and control statements

Source: Internet
Author: User
  1. Built-in functions
    • INT (x, [, base]): converts a value or string to a decimal number. When base has parameters, X must be a string and base-based. Print int ('20140901', 8) #12345
    • All (): If all functions are not 0, or if the element is null, true is returned. Otherwise, false is returned.
    • The range () function generates only an object that can be iterated, and the output is not a list. Use List (range () to iterate the objects returned by range into a list.
    • Format (value [, format_spec]):
    • Format (x, '6. 3f'): In the 6.3f output format, the floating point number is output with a total width of 6 digits and three decimal places.
    • If the actual number of decimal places is less than 3, 0 is added. If the number of decimal places exceeds 3, the excess part is rounded to the nearest digit.
    For example, if the total width (including one decimal point, plus three decimal places, if there is a sign bit "-", it is also regarded as one digit) is less than 6 digits, then fill in the front space; if the total width exceeds 6 bits, the output is based on the actual width.
    • The "" in the print () function must be separated from the variable name.

2. Statement Structure

  • Single Branch (if statement), double branch (if, else statement), and multiple branch (if, Elif, else ). Multiple branches only execute the first statement that is true. Therefore, the conditional order of multiple branches affects the execution result of the program.
  • Loop Structure: traversal loop (for), conditional loop (while, do not know how many times to use this method ).

The commonly used operator = In a statement is used to determine whether two objects are equal, not whether the values are equal. The letter W = W. Conditional loops are implemented by one condition. A processing operation must be provided in the loop body so that the loop can end. The conditional calculation result cannot always be true. Otherwise, the loop is stuck in an endless loop.

3. nested loop structure:

Pay attention to the level of the statement or statement forging to identify whether it is an outer loop or an inner layer.

 

The blue font is important and hard to understand.

 

Built-in functions and control statements

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.