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]
Code block else: code block
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]
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")