Python learning [Day2]while loop and execution flow, formatted output, operator

Source: Internet
Author: User

1. While loop

        while condition:              code block (loop body)          execution Flow:             1. Determine if the condition is true. If it's true. Executes the code block             2. Judge again whether the condition is true ...             3. When the condition is false. Execute else jumps out of the loop. The loop ends with an example of a few simple while loops: (1): The sum of the numbers within 1~100: num = 1 sums = 0 While  num <= 100:sum = sum + num num + = 1 print (sum) (2): 1-2+3-4.......99 so the sum of the numbers: num = 1 sum = 0 while num          < 100:if num% 2 = = 0:sum = sum-num if num% 2! = 0:sum = sum + num num + = 1 print (sum)     4. break    end loop. Stops the current loop    5. continue   ends the current cycle. Continue with the next loop  &nBsp 2. Formatted output         %s: A placeholder for a string that can place any content (number) A for the variable format as follows: print ("haha haha%s"% a) &nbsp ;         %d: Placeholder for numbers (IBID.)    3. Operators          logic operations:         and    and the meaning. Both left and right values must be true. The result of the operation is true         or    or meaning. The left and right sides have one that is true. The result is true. All is false. The result can be false         not   non-meaning. It turned out to be false. Now is true .   not true or false, not false both true   

Python learning [day2]while loop and execution flow, formatted output, operator

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.