Explanation of the basic data types of variables in Python: if and while statements

Source: Internet
Author: User
This article describes the basic data types of variables in Python. if and while statements. This article describes the basic data types of variables in Python. if and while statements.

Variable name: it can only contain numbers, letters, and underscores and cannot start with a number. variable name cannot be a keyword in python.

Basic data types: numbers, strings, and Boolean values (True/False)

[If condition statement]

If condition:

Code block

Else:

Code block

If condition 1:

Code block

Elif condition 2:

Code block

Elif condition 3:

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]

Returns all positive integers less than 10]

import time n = 1flag = Truewhile flag:     print(n)     if n ==10:          flag == False     n=n+1     time.sleep(1)print("end")

[Break] jumps out of the current loop, and the code below break is no longer executed.

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

[Continue] jumps out of this loop and continues the next loop.

while True:     print("123")          continue     print("456")

The above is a detailed description of the basic data types of variables in Python if and while statements. For more information, see other related articles in the first PHP community!

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.