Cloud computing Python Automation: Operators and expressions

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

Operator is used to execute program code operations, and operations are performed on more than one operand item. For example: 2+3, whose operands are 2 and 3, while the operator is "+".

What is an expression:

An expression is a combination of numbers, operators, numeric grouping symbols (parentheses), free variables, and constraint variables that can be obtained by means of a meaningful arrangement of values. A constraint variable is assigned a value in an expression, while a free variable can specify a value outside of an expression.

Python operator Classifications:

Arithmetic operators

Compare (relational) operators

Assignment operators

logical operators

Bitwise operators

Member operators

Identity operator

Arithmetic operators:

The following assumes that the variable A is 10 and the variable B is 20:

+: Add-two objects added.

Example: A + B output result 30

-: minus-gets a negative number or one count minus the other.

Example: A-B output result-10

*: Multiply by two numbers or return a string that is repeated several times.

Example: A * b output result 200 |

/: Except-X divided by Y.

Example: b/a output result 2

%: Modulo-Returns the remainder of the division.

Example: b% A output result 0

* *: Power-Returns the Y power of X.

For example: A**b is 10 of the 20-time side, the output result 100000000000000000000

: Take division-Returns the integer part of the quotient

For example: 9//2 output result 4, 9.0//2.0 output 4.0

Attention:

>> 5/2//No decimal place when the division operation gets an integer

2

>> 5.0/2

2.5

Compare (relational) operators:

The following assumes that the variable A is 10 and the variable B is 20:

| == | Equals-compares objects for equality | (A = = B) returns FALSE.

| != | Not equal-compares two objects for unequal | (A! = B) returns TRUE.

| <> | Not equal-compares two objects for unequal | (a <> B) returns True. This operator is similar to! =.

| > | Greater than-returns whether x is greater than Y | (A > B) returns FALSE.

| < | Less-Returns whether x is less than Y. All comparison operators return 1 for true, and return 0 for false. This distinction is equivalent to the special variable true and false. Note that these variable names are capitalized. | (A < B) returns TRUE.

| >= | Greater than or equal-returns whether X is greater than or equal to Y. | (a >= B) returns FALSE.

| <= | Less than or equal-returns whether X is less than or equal to Y. | (a <= B) returns True.

Assignment operators:

The following assumes that the variable A is 10 and the variable B is 20:

| = | Simple assignment Operator | c = A + B assigns the result of the operation of A + B to c

| += | Addition Assignment Operator | c + = A is equivalent to C = C + A

| -= | Subtraction Assignment Operator | C-= A is equivalent to C = c-a

| = | multiplication Assignment operator | c = A is equivalent to C = c * A

| /= | Division Assignment Operator | C/= A is equivalent to C = c/a

| %= | Modulo assignment Operator | C%= A is equivalent to C = c% A

| =| Power Assignment operator | c = A is equivalent to C = c * * A

| //=| Take integer assignment operator | C//= A is equivalent to C = c//A

Cloud computing Python Automation: Operators and expressions

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.