Getting started with Python-Process Control __python

Source: Internet
Author: User

This article describes process control (conditional statements and circular statements) in Python

1, conditional statement

(1) only if

A=true
If a:
    print ("A is established")
    print ("I know A is established")

(2) If---else

A=true
If a: print ("A is established"
    )
    print ("I know A is established")
else:
    print ("A does not set up")

(3) If---elif---else

A=false
b=true
If a:
    print ("AAA")
elif B:
    print ("bbbb")
else:
    print ("CCC")

2. Circular statements

(1) for

Similar to the use of foreach

letter=[111, "Zhangshan", 7878,99] for Le in letter
:
    print (LE)
Traversing using the subscript index

letter=[111, "Zhangshan", 7878,99,88] for
index in range (len):
    print (Letter[index))
With else for, when the condition is not true, execute else
letter=[111, "Zhangshan", 7878,99] for Le in letter
:
    print (le)
else:
    print ("Loop over")

(2) While note: There is no do---in python while

General while

A=1 while
a<=4:
    print (a)
    a+=1
A while with else, executing else when the condition is not true

I=0 while
i<5:
    print ("i")
    i+=1
Else:
    print ("Conditional not set")

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.