12th. If branch statement expression constructs

Source: Internet
Author: User

1, conditional judgment: Boolean expression: 0 or 1, not 0 is considered to be true

2, relational expression: >,<,==,!=,>+,<=

3, logical expression: and Or not

4,in,not in

True, False is a python built-in variable

Syntax structure:

If condition:

print ' True '

Else

print ' False '

Boolean expression:

EG1:

If True:
print ' OK '
Else
print ' No '

EG2:

If 0:
print ' OK '
Else
print ' No

EG3:

If 13:
print ' OK '
Else
print ' No

EG4:

If ' Baidu ':
print ' OK '
Else
print ' No '

Relational Expressions:

10>9------True-----> Boolean expression 1 (True)

10<9------False----> Boolean expression 0 (false)

EG1:

Record=int (raw_input (' plz input your record: '))
If record>=90:-------------relational Expressions: relational operators
print ' good! '
Else
print ' bad!

EG2:

Sex=raw_input (' plz input your sex: ')
If sex== ' male ':-------------relationship expression: relational operator

print ' Man '
Else
print ' Woman '

Logical expressions:------------Learn to construct more complex expressions with logical expressions

And, or, binocular operators

Not single-mesh operator

EG1:

Sex=raw_input (' plz input your sex: ')
If not sex== ' male ':-------relational expression-----Logical expression------Boolean expression
print ' Man '
Else
print ' Woman '

EG2:

Sex=raw_input (' plz input your sex: ')
If sex== ' male ' or sex== ' m ' or sex== ' man ' or sex== ' man ':----or one is true;
print ' Man '
Else
print ' Woman '
















12th. If branch statement expression constructs

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.