Python Basics-Operators

Source: Internet
Author: User
Tags arithmetic

Computer can be carried out many kinds of operations, can not only subtraction so simple, the operation by category can be divided into arithmetic operations, comparison operations, logical operations, assignment operations, member operations, identity operations, bit operations, today we temporarily only learn arithmetic operations, comparison operations, logical operations, assignment operations.


Arithmetic operations: Suppose a=20 b=10

Operator Operator description Instance
+ Two objects added A + b outputs a result of 30
- Subtraction of two objects A-B outputs 10
* Multiply two objects A * b outputs a result of 200
/ Divide two objects A/b Outputs a result of 2.0
% Modulo returns the remainder after dividing A% b outputs a result of 0
** Power A * * b output 20 of 10 power
// Division of integers returns the integer part after dividing
Example: 9//2 result is 4


Comparison operation: Suppose A=20 b=10

Operator Operator description Instance
== Equals comparison of two objects equal A = = B result is false
!= does not equal the comparison of two objects A! = B results are true
<> does not equal the comparison of two objects A <> b results are true
> Greater than compare which object has a larger value A > B results are true
< Less than compare which object has a smaller value A < b result is false
>= Greater than or equal A >= b result is true
<= Less than or equal A <= b result is false


Assignment operation:

Operator Operator description Instance
= Simple assignment
A = 10 assigns a value of 10 to the A variable
+= Addition assignment Operation #自加运算
A + = 10 equates to a=a+10
-= Subtraction Assignment Operation #自减运算 A-= 10 equates to a=a-10
*= Multiplication Assignment Operation #自乘运算 A *= 10 equates to a=a*10
/= Division assignment Operation #自除运算 A/= 10 equates to A=A/10
%= Modulo assignment operation A%= 10 equates to a=a%10
**= Power Assignment operation A **= 10 equates to a=a**10
//= Rounding Assignment operation A//= 10 equates to A=A//10


Logical operation: Suppose A=20 b=10

Operator
Operator description Instance
and
"with" condition 1 and Condition 2 are satisfied for true A>10 and b<20 results are true
Or "or" condition 1 or Condition 2 satisfies one is true a>15 or b>15 result is true
Not Non- Not a>15 result is false


Python Basics-Operators

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.