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")