About simple operations, binary operations, logical operators, member operators, identity operators

Source: Internet
Author: User

A simple operation

>>>

2

>>> 2-1

1

>>> 2*3

6

>>> 2/1

2.0

>>> 5%4 <==== Returns the remainder of a division

1

>>> 2**2 <==== Power Sub-party

4

>>> 5//2 <==== about the pick-up, take only the whole number of parts

2

>>> 5==5

True

>>> 5!=4 <==== about not equal to

True

>>> 5>4

True

>>> 4<5

True

>>> 5>=5

True

>>> 4<=4

True


About binary operations

Operator Description Instance

& Bitwise AND Operator 10&50 The result is 2 if A is 00001010 b 00110010 means that the same bits in A and B are true and 1

| The bitwise OR operator 10|50 results in a result of 58 if A is 00001010 B for 00110010 that is the same bit in A and B as long as one is true, it is 1.

^ Bitwise XOR operator 10^50 The result is 1=56 if A is 00001010 B for 00110010 that is the same bit in A and B as long as there is a true is true is 1, all true is False represents 0, all false is False representative 0

>> Right Move operator If A is 00001010, the result is 00000101 for 5, according to the right shift.

<< left move operator if A is 00001010 and left one, the result is 00010100 for 5.


logical operators

Operator description

and Boolean "and" if X is False,x and Y returns false

or boolean "or", if X is true, it returns true

Not Boolean "non", if X is true, it returns false


Member operators

Operator

Inch

Not in

Example

The number 1:

name=[' Alex ', ' Rain ']if ' Jack ' in Name:print ("Pengchun was Handsome") Else:print ("Pengchun is very handsome")
Results Pengchun is very handsome

The number 2:

name=[' Alex ', ' Rain ']if ' Alex ' in Name:print ("Pengchun was Handsome") Else:print ("Pengchun is very handsome")

Results Pengchun is handsome


Identity operator

Is

is not

Example:

The number 1

The If Type (3) is Int:print ("Pengchun is Handsome") results in Pengchun is handsomethe number 2 if Type (3) was not List:print ("p Engchun is handsome ") results Pengchun is handsome

About simple operations, binary operations, logical operators, member operators, identity operators

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.