Detailed description of the variable basic data type if, while statement in Python

Source: Internet
Author: User
This article details the variable basic data type if, while statement in Python

Variable name: can only consist of numbers, letters, underscores and cannot start with a number; variable names cannot be keywords inside python

Basic data type: Number, String, Boolean (True/false)

"If condition statement"

If condition:

code block

Else

code block

If condition one:

code block

Elif Condition Two:

code block

Elif Condition Three:

code block

Else

code block

"Simple User logon program"

Name = Input ("Username:") pwd = input ("Password:") if name = = "ZJW" and pwd = = "123"    print (' yes ') Else:    print (' No ')

"While Loop statement"

While condition:

code block

Instance

"All positive integers within output 10"

Import time n = 1flag = Truewhile flag:     print (n)     if n ==10:          flag = = False     n=n+1     time.sleep (1) print ("E nd ")

"Break" is used to jump out of the current loop, and the code below the break no longer executes

n =  1while True:     print (n)     if n ==10:          breakn=n+1

"Continue" is used to jump out of this loop and continue the next cycle

While True:     print ("123")          continue     print ("456")
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.