Getting Started Tutorial 2

Source: Internet
Author: User

Here is a very useful little tutorial basically remember, but it takes a long time to review

if sentence (judgment statement)---------------------------------------- ---------------
i = 1
if i > 0:
print ' positive i '
i = i + 1
elif i = = 0:
print ' I is 0 '
i = i * ten
else:
print ' negative i '
i = i-1
print ' New I: ', I

--------------------------------------------------for statement (Loop)-----------------------------------------------------------
For I in range: # for element in sequence:
Print I**2 # Action statement

result:1,4,9,16,25,36,49,64,81

-------------------------------------------------while Statement (Loop)--------------------------------------------------------------
While condition:
Statement

As an example:
>>> i = 5 # give variable i assign value
>>> While I < 10:
Print I
i = i +1

Result
5
6
7
8
9

---------------------------------------------------------interrupt-continue--------- ------------------------------------------------------
> >> for I in range:
if I = = 2:
Continue #同一循环的某一环, continue, skip this loop and proceed to the next loop
print I

result:
0
1
3
4
5
6
7
8
9

---------------------------------------------------------Interrupt-break-------------------------------------------------------- -------
>>> for I in range (10):
if i = = 2:
Break #停止整个循环, do not proceed to the next loop
Print I

Result
0
1

Getting Started Tutorial 2

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.