Getting started with Python in the indent magic

Source: Internet
Author: User

Idx=1sum=0 while idx<=100:    sum=idx+sum    idx=idx+1  Print (' sum = ', sum)

======================== restart:d:/pythondata/11.py ========================
Sum 100 = 5050

Idx=1sum=0 while idx<=100:    sum=idx+sum    idx=idx+1    print (' sum = ', sum)= 4851= 4950100 = 5050

The first Python experiment was recorded to look at the same code, showing different results

This is because the 2nd piece of code, theprint indent is represented in the loop body, so each cycle is printed once.

The 1th code, printdoes not indent, means that the code is printed once after the loop is complete.

Getting started with Python in the indent magic

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.