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!