current position:Home>Python 3 process control statement
Python 3 process control statement
2022-02-01 13:04:53 【Work hard tomorrow】
「 This is my participation 11 The fourth of the yuegengwen challenge 27 God , Check out the activity details :2021 One last more challenge 」
Python The code is executed in a top-down order .
Through process control statements , You can change the execution order of the program , You can also have the specified program execute repeatedly .
Process control statements are divided into two categories : Conditional statements , Loop statement .
1. Conditional statements (if sentence )
if sentence
grammar :if Conditional expression : sentence
By default ,if Statement controls only the statement that follows , If you want to if Control multiple statements , Then you can if Followed by a code block ( Code blocks start with indents , Until the code returns to its previous indentation level );
Two indentation methods :1. Use tab key ;2. Use four spaces
if True:
print(123)
print(456)
input(), This function is used to get the user's input ; After calling , The program will be suspended immediately , Waiting for user input .
When user input is complete , Click enter to continue the downward execution ;
When user input is complete , Its input will be returned with a value ( character string ) Form return of ;
Function can set a string as an argument , This string will be displayed as prompt text ;
input() It can also be used to temporarily prevent the program from ending
a = input(' Please input anything :')
print(' The user input is :',a)
if-else sentence
grammar :( Only one block of code is executed )
if Conditional expression :
Code block
else:
Code block
if-elif-else sentence
grammar :
if Conditional expression :
Code block
elif Conditional expression :
Code block
elif Conditional expression :
Code block
elif Conditional expression :
Code block
else :
Code block
Copy code
2. Loop statement
while loop
grammar :while Conditional expression :
Code block
else :
Code block
i = 0
while i < 10 :
i +=1
print(i)
else :
print('else Code block in ')
break: Used to immediately exit a loop statement ( Include else)
continue: Used to skip the current loop
pass: Used to occupy a place in a loop or judgment statement
i = 0
while i < 5 :
i += 1
if i == 2:
continue
print(i)
Copy code
Loop nested cases
Print triangles
python How to write it :
i = 0
while i < 5 :
j = 0
while j < i + 1 :
print('*',end = '')
j += 1
print()
i += 1
javaScript How to write it :
for (var i = 0; i < 5; i++) {
for (var j = 0; j < i + 1;j++){
document.write('*')
}
document.write('<br/>')
Copy code
copyright notice
author[Work hard tomorrow],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202011304512558.html
The sidebar is recommended
- Python logging log error and exception exception callback method
- Learn Python quickly and take a shortcut~
- Python from 0 to 1 (day 15) - Python conditional judgment 2
- Python crawler actual combat, requests module, python to capture headlines and take beautiful pictures
- The whole activity collected 8 proxy IP sites to pave the way for the python proxy pool, and the 15th of 120 crawlers
- Why can't list be used as dictionary key value in Python
- Python from 0 to 1 (day 16) - Python conditional judgment 3
- What is the python programming language?
- Python crawler reverse webpack, a real estate management platform login password parameter encryption logic
- Python crawler reverse, a college entrance examination volunteer filling platform encrypts the parameter signsafe and decrypts the returned results
guess what you like
-
Python simulated Login, selenium module, python identification graphic verification code to realize automatic login
-
Python -- datetime (timedelta class)
-
Python's five strange skills will bring you a sense of enrichment in mastering efficient programming skills
-
[Python] comparison of dictionary dict, defaultdict and orderdict
-
Test driven development using Django
-
Face recognition practice: face recognition using Python opencv and deep learning
-
leetcode 1610. Maximum Number of Visible Points(python)
-
Python thread 03 thread synchronization
-
Introduction and internal principles of Python's widely used concurrent processing Library Futures
-
Python - progress bar artifact tqdm usage
Random recommended
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
- leetcode 1606. Find Servers That Handled Most Number of Requests(python)
- leetcode 1611. Minimum One Bit Operations to Make Integers Zero(python)
- 06python learning notes - reading external text data
- [Python] functions, higher-order functions, anonymous functions and function attributes
- Python Networkx practice social network visualization
- Data analysis starts from scratch, and pandas reads and writes CSV data
- Python review (format string)
- [pandas learning notes 01] powerful tool set for analyzing structured data
- leetcode 147. Insertion Sort List(python)
- apache2. 4 + windows deployment Django (multi site)
- Python data analysis - linear regression selection fund
- How to make a python SDK and upload and download private servers
- Python from 0 to 1 (day 20) - basic concepts of Python dictionary
- Django -- closure decorator regular expression
- Implementation of home page and back end of Vue + Django tourism network project
- Easy to use scaffold in Python
- [Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)
- [Python] function decorators and common decorators
- Explain the python streamlit framework in detail, which is used to build a beautiful data visualization web app, and practice making a garbage classification app
- Construction of the first Django project
- Python crawler actual combat, pyecharts module, python realizes the visualization of river review data
- Python series -- web crawler
- Plotly + pandas + sklearn: shoot the first shot of kaggle
- How to learn Python systematically?
- Analysis on several implementations of Python crawler data De duplication
- leetcode 1616. Split Two Strings to Make Palindrome (python)
- Python Matplotlib drawing violin diagram
- Python crawls a large number of beautiful pictures with 10 lines of code
- [tool] integrated use of firebase push function in Python project
- How to use Python to statistically analyze access logs?