Python notes (i)-do not misuse ++i 、--I

Source: Internet
Author: User

Ilocker: Focus on Android Security (novice) qq:2597294287

++i can also be written in Python, but the meaning is completely different from C + +. Python's ++i is not to increment I by 1, but rather to put 2 plus sign in front of I, so I will not change the value.

1 i = 02 while I < 5:3     print(++i)

So the above loop will be a dead loop that has been printing 0.

Similarly, the meaning of-I is not self minus 1, but two negative minus positive.

1 i = 52 while I > 0:3     print(-I.)

This is also a dead loop that has been printing 5.

i++, i--is a syntax error in Python, because a plus or minus sign is followed by a number or an shaping variable.

Learning materials: Writing high-quality code-91 tips for improving Python programs

Python notes (i)-do not misuse ++i 、--I

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.