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

高洛峰
Release: 2017-03-14 15:18:45
Original
2018 people have browsed it

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')
Copy after login
[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")
Copy after login
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
Copy after login
[continue

] Used to jump out of this loop and continue the next loop

while True:
     print("123") 
         continue
     print("456")
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template