Home >Backend Development >Python Tutorial >Detailed explanation of the basic data types of variables in Python if and while statements

Detailed explanation of the basic data types of variables in Python if and while statements

高洛峰
高洛峰Original
2017-03-14 15:18:452053browse

This article explains in detailPythonVariablesBasicData types ifwhileStatement

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

: code block

## 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 loop

Statement]

while condition:

                  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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn