In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Xiaobian to share with you how to use the if statement, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
If the structure of the statement, pay attention to the colon in the syntax, determine whether it is equal to the use of double equals, meet the conditions to use indentation
If it means, judge. In a programming language, an if statement is used to determine whether a given condition is satisfied and to execute a block of code according to the result of the determination. The return value of the if statement is true or false (True or False), which can be stored in a bool variable, which takes up one byte.
Syntax of the if statement
The syntax format is as follows:
If judgment conditions: Execute statement else: execute statements
If is followed by the judgment condition, when the judgment condition is true, the following execution statement will be executed. When the judgment condition is not true, the execution statement in else will be executed. It should be noted that the judgment statement must be followed by a colon: , otherwise an error will be reported.
A simple if... The else statement is used to determine whether the variable num is less than 10. If num is less than 10, the execution statement that follows the if statement is printed. If this condition is not met, print the execution statement below else.
If you don't understand, let's look at a small example:
#Define a variable to store score = 100 #Determine if this variable equals 100if score == 100: print("Congratulations on your 100")else: print("Keep working hard")#Output: Congratulations on your 100% test
In the above two examples, we use greater than = greater than or equal to = 11 in the judgment statement: print("True")else: print("False")
2. Write a judgment sentence based on what you learned today. Give a grade to your performance today. A score of 60 or less indicates a failing grade, 60 (inclusive) to 79 (good), 80 (inclusive) to 99 (excellent), and 100 (perfect).
That's all for "How to use the if statement". Thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.