Python programming 5th-if statement

Source: Internet
Author: User

The Tutorial we bring to you today is "Python programming series tutorial 5th about if statements": Generally, when you read other people's Python code, it may be found that this # _ * _ coding: UTF-8 _ * _ is to use Chinese in Python, specifying that the character set used by the current Python script is UTF-8 encoding. Python has three basic statements to control the process of the program. They are the if statement, for statement, and while statement. In the next course, we will introduce it one by one. Let's take a look at the first If statement. before talking about this, we should first learn another data type, called the bool type, to indicate true or false. It is used for judgment. True indicates True, False indicates False. For example, is Nana a puppy? If the result of this execution is True, I will use True to represent it. If it is False, we will use False to represent it. ALT + P = indicates that the value is assigned = indicates that the value is 5> 3. If the result is True, the if statement is used together with the else statement. If indicates If. If 5> 3, then we output a sentence. Else indicates otherwise, when the if condition judgment statement is False, the code block in else will be executed. Emphasize: the code is reduced. Now let's take a look at the reg. py registration script written in the previous lesson. We now add an item for it to allow users to enter the age. If the age is between 18 and 120, we assume that the age is valid and can be registered, otherwise, we will output a sentence to the user. Your age is invalid. Three logical operators And, or, not multi-branch selection structure IfElifElif... Else Xiao Ming exam score> 90 excellent 80-90 good between 70-80 medium below 70 difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.