Python conditional statements and data types (i)

Source: Internet
Author: User

 

Cases:

if 1=1, then it will output "Hello World" otherwise    Output "Hello penphy"

Code block:

1 if Conditions: 2   Print("helloWorld")3else:4  ("Error")

Note:The indent below the if is also a space, which represents the code block below if. (Indentation is not correct, will be error)

1 if 1 = = 1 :2     print("helloWorld")3  Else:4     print ("hello penphy" )

  The 1=1 condition is true, so the second line of code is executed otherwise the condition does not hold the code of line fourth

1 if1 = = 12     if2 = = 23         Print("Hello World")4         Print("Hello Seattle")5     Else:6         Print("Hello Pengfei")7 Else:8     Print("Hello penphy")

  

The above two graphs can be nested if else.

  

1INP = input ('Please enter the name of the member:')2 ifINP = ="Senior Member"3     Print('Beauty')4 elifINP = ="Platinum Member"5     Print('Sports car')6 elifINP = ="Platinum Members"7     Print('First-line actress')8 Else:9     Print('Chengguan')Ten  One Print('Service Start ...')

---According to the above conditions, if you do not enter these membership words, will automatically output Chengguan

Summarize:

1. If basic statement

If condition :

Internal code block

Internal code block

Else

... #内部代码块 #

Print (' .... ')

Execute if execution condition is met

2. If support nesting

3 elif Statements

Extra supplement: Pass statement

Pass

If 1 ==1:

Pass

Else

Print (' Get out ')

Note: if 1 = = 1, then the program will skip execution

    

            

            

Python conditional statements and data types (i)

Related Article

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.