Python -- variable | basic data type | if, while statement, pythonwhile

Source: Internet
Author: User

Python -- variable | basic data type | if, while statement, pythonwhile
Variable name: it can only contain numbers, letters, and underscores and cannot start with a number. Variable names cannot be basic data types of keywords in python: number, String, Boolean value (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")

 

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.