What is an operator? The role of the Python operator and the meaning of each Python operator

Source: Internet
Author: User
Tags arithmetic operators bitwise operators

What is an operator?

This section mainly describes the Python operators . To give a simple example 4 +5 = 9. In the example, 4 and 5 are called operands, and "+" is called an operator.

The Python language supports the following types of operators:

1. Arithmetic operators

2. Compare (relational) operators

3. Assignment operators

4. Logical operators

5. Bitwise operators

6. Member Operators

7. Identity operator

8. Operator Precedence

Next, let's learn about Python's operators.

Python arithmetic operators

The following hypothetical variables: a=10,b=20:

Operator
Describe
Instance
+
Add-Two objects added A + B output result 30
- Minus-get negative numbers or one number minus the other -B Output Result-10
* Multiply by two number or return a string that is repeated several times A * b output result 200
/ Except-X divided by Y B/A Output Results 2
%
Modulo-Returns the remainder of the division B% A output result 0
**
Power-Returns the Y power of X A**b is 10 of 20, output 100000000000000000000
// Rounding-Returns the integer portion of the quotient (rounded down) 9//2 output result 4, 9.0//2.0 output 4.0

The following example shows the operation of all the arithmetic operators of Python:

#!/usr/bin/python#-*-coding:utf-8-*-a = b = ten c = 0 c = a + b print "1-c value:", c c = value of "A-D  print" 2-c For: ", c c   = a * b print" 3-c value is: ", c   C = A/b print" 4-c value is: ", c   C = a% b print" 5-c value is: ", c  # Repair The change amount A, B, c a = 2 b = 3 c = a**b print "The value of 6-c is:", c  A = ten b = 5 c = a//b  print "7-c value is:", C

The result of the above example output:

The value of the 1-c is: 31

The value of the 2-c is: 11

The value of the 3-C is: 210

The value of the 4-C is: 2

The value of the 5-c is: 1

The value of the 6-C is: 8

The value of the 7-c is: 2

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.