In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to use the program flow control statement in Python, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this Python program flow control statement. Let's take a look at it.
I. Branch statement
Only if is the branch statement in Python. Elif... Else... Without switch... Case... Officials believe that if... Else... Has been able to meet the demand. The function of the branch statement is to make a judgment and filter out the data that meets a certain situation, in other words, to do different things in different situations.
# single branch structure if 80 > 70: print ('invincible 666') # Multi-branch structure s=int (input ("Please enter your exam results:") if 100 > = s > = 90: print ("your grades are invincible") if s > 95: print (' your grades are supreme') else: print ('your grades are lower than ten thousand people') elif 90 > s > 60: print ('your grades are supreme') Else: print (your grades are not qualified Or enter irregular') # conditional expression [similar to the ternary operator in C++ language] print ("I was right" if 90 > 80 else "I was wrong") # placeholder and object Boolean value # each object has a Boolean value, so the object can be put directly into the conditional statement, as a discrimination condition # python is only 0 or empty false# placeholder in bool is when you don't know what's written there. However, the compiler does not report passss=int (input ("input object:")) if ss: print ('yes') passelif ss > 1: print (' no') else: pass II, looping statement 1. Iterable object
Before talking about the loop statement, let's talk about what is an iterable object. The iterable object returns one element at a time, which mainly contains sequences, file objects, iterator objects, and generator functions. An iterator is a collection of data that can be iterated by an object. Its main feature is that it includes the methods _ _ iter__ () and _ _ next__ (), which can realize the iterative function. The generator is a function that uses the yield statement to produce a value one at a time. The range object is an iterator object. In Python, loop statements are still divided into while and for loops.
2.while cycle
While is followed by a loop condition. In the following example, I is a loop variable. When the loop variable does not meet the loop condition, it exits the loop. The following example prints the sum of 1-100:
The code is as follows:
I=1mysum=0while i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.