Python Basics (3) If_else, for, while, break, and continue

Source: Internet
Author: User

1. If ... else
1 a=62if a>=5:3     print("TheA is bigger than 5")4Else:5     print( " The A is smaller than 5 ")

2. For loop

1 # for I in range: #默认从0开始, stepping is 1 equivalent to C language for (i=0;i<10;i++) 2  for  in Range (1,10,3):# starting from 1, the step is 33     print("Loop:  ", i)

3. While loop

1 count=02 while True:3     print("  You are the wind I am the sand, wrapped around the horizon ... " , Count) 4     Count +=1

4. Break and Continue

1 #Break to completely exit this layer loop2  whileTrue:3     Print("break:123")4      Break5     Print("456")6 7 #continue is used to exit this loop and continue the next cycle8  whileTrue:9     Print("continue:123")Ten     Continue One     Print("456")

5, While+else

# Unlike other languages else, which is usually only the same as if, there is a while ... else statement in Python, and the else function after the while is the
When the while loop executes normally and the middle is not interrupted by a break, the statement after the else is executed

Python Basics (3) If_else, for, while, break, and continue

Related Article

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.