Python Basic 5-operator

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise bitwise operators logical operators

First, arithmetic operators

Arithmetic operators Assignment operators Specific description Example Add
+ += Additive operations X+=1 equivalent to X=x+1
- -= Subtraction operation All assignment operators ibid.
* *= Multiplication operations
/ /= Division operation
% %= Modulo arithmetic
** **= Power operation 2**3=8
// //= The integer operation 9//2=4

Two-bit operators

Bitwise operators Specific description
& Bitwise AND operation, 1&1=1, the remaining 0
| bitwise OR operation, 1 is 1, otherwise 0
^ Bitwise XOR, same as 0, different 1
~ bitwise NON, ~0=1,~1=0
<< Left-shift operation, all bits shifted to the left
>> Right shift operation, all bits shifted right

Third, comparison operators

Comparison operators Specific description
==
! = Inequality operator
<> Unequal operators, same! =
<
>
<=
>=

Four, logical operators

logical operators Specific description
and Logic and operations
Or Logical OR operation
Not Logical non-operation

Five, string operators

Operator Specific description
+ String connection
* Repeating output string
[] Get the position character by index, index starting from 0
[Start,end] Intercept part of a string, from start to End-1
Inch A member operator that returns true if the string contains the given character
Not in Member operator, which returns true if the string does not contain the given character
R or R

Specifies the original string, which means that all strings are used directly as literal meanings, without escape characters,

Special characters or characters that cannot be printed. The first quotation mark of the original string is preceded by the letter R or R

the precedence of the operator (top-to-bottom represents the high and low of the operation priority)

Meta operator Specific description
**
~, +,- Here the +,-refers to the plus or minus
*、/、%、//
+,- Here the +,-refers to the addition and subtraction
>>, <<
&
^, |
>, = =,! =
%=,//= 、...... All assignment operators
is, is not Identity operator
In, not in Member operators
Not, or, and logical operators

Python Basic 5-operator

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.