Home > Article > Backend Development > Detailed explanation of the basic data types of variables in Python if and while statements
This article explains in detailPythonVariablesBasicData types if、whileStatement
Variable name: can only be composed of numbers, letters, and underscores and cannot start with a number; variable names cannot be python internal keywords
Basic data types: numbers, String, Boolean value (True/False)
[if conditional statement]
if condition:
Else ## counter Conditions 1: code block Elif condition 2: Code block elif condition three: Code block else: Code block
[Simple
User Login
Program]name = input("Username:") pwd = input("Password:") if name == "zjw" and pwd == "123" print('yes') else: print('no')[while loopStatement] Code block 【Example】【Output all positive
integers within 10
】import time n = 1 flag = True while flag: print(n) if n ==10: flag == False n=n+1 time.sleep(1) print("end")【break] Used to jump out of the current loop, and the code below break will no longer be executed
n = 1 while True: print(n) if n ==10: break n=n+1[continue] Used to jump out of this loop and continue the next loop
while True: print("123") continue print("456")
The above is the detailed content of Detailed explanation of the basic data types of variables in Python if and while statements. For more information, please follow other related articles on the PHP Chinese website!