Python's basic statement

Source: Internet
Author: User

If condition statement

(1) If condition judgment: (colon)

If 1==1:

Print (' Really nothing ')

Else

Print (' It will be later ')

Description of the # # # code block: In the same column as the code block, as above, if the print is a block of code.

# # #一般为空4格为标识, or press the TAB key directly.

(2) If the nesting:

If n==1:

Print (' haha ')

If n==2:

Print (' hehe ')

Else

Print (' hehe ')

Else

Print (' haha ')

# #注意代码块 ...

(3) Use of If elif:

If n==1:

Print (' Hello ')

Elif n==2:

Print (' Years later ')

Elif n==3:

Print (' True fragrance ')

Else

Print (' SB ')

If you want direct else, you need to:

If n==1:

Pass keyword: Do not perform the current direct skip.

else:

Print (' SB ')

How to use the while:

(1) While Count ==1:

Print ("haha")

You also need to be aware of code blocks when you use them.

(2) Use of while else

While Count <10:

Print ("haha")

Count =count +1

Else

Print ("hehe")
Pay attention to the code block when using

(3) Continue break

While count<10:

If count==7:

Count=count+1

Print (' haha ')

Continue

Else

Print (' haha ')

Count=count+1

The use of continue is that when the if is met, if is encountered continue, the if is returned and the execution continues. That is, when =7, continue to the else output haha

Break, the effect of break is to jump out of all loops.

To the previous supplement:

(1) When a real string can only be "" "" "" "" "in several ways

  

Python's basic statement

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.