What are the python operation symbols?

zbt
Release: 2023-12-11 14:59:22
Original
4106 people have browsed it

Python operation symbols include addition operator (), subtraction operator (-), multiplication operator (*), division operator (/), integer division operator (//), remainder operator ( %), power operator (**), equal operator (==), not equal operator (!=), greater than operator (>), less than operator (<), greater than or equal to operator (> ;=), less than or equal to operator (<=), AND operator (and), or operator (or), NOT operator (not), bitwise AND operator (&), etc.

What are the python operation symbols?

The operating system for this tutorial: Windows 10 system, Python version 3.11.4, DELL G3 computer.

There are a variety of operators in Python that are used to perform various operations, including arithmetic operations, comparison operations, logical operations, and bit operations. The following are commonly used operators in Python:

1. Arithmetic operators:

  • Addition operator ( ): used to perform two Number addition operation.

  • Subtraction operator (-): used to perform the subtraction operation of two numbers.

  • Multiplication operator (*): used to perform the multiplication operation of two numbers.

  • Division operator (/): used to perform the division operation of two numbers, and the result is a floating point number.

  • Integer division operator (//): used to perform an integer division operation between two numbers, and the result is an integer.

  • Remainder operator (%): used to calculate the remainder after dividing two numbers.

  • Power operator (**): used to perform exponential operations on a number.

2. Comparison operators:

  • Equal operator (==): used to check two numbers are equal.

  • Inequality operator (!=): used to check whether two numbers are not equal.

  • Greater than operator (>): used to check whether the left operand is greater than the right operand.

  • Less than operator (<): used to check whether the left operand is less than the right operand.

  • Greater than or equal to operator (>=): used to check whether the left operand is greater than or equal to the right operand.

  • Less than or equal to operator (<=): used to check whether the left operand is less than or equal to the right operand.

3. Logical operators:

  • And operator (and): used to check whether multiple conditions Satisfied at the same time.

  • Or operator (or): used to check whether at least one of multiple conditions is satisfied.

  • Non operator (not): used to reverse the result of a condition.

4. Bitwise operators:

  • The bitwise AND operator (&): used to perform two Bitwise AND operations on numbers.

  • The bitwise OR operator (|): used to perform the bitwise OR operation of two numbers.

  • Bitwise XOR operator (^): used to perform bitwise XOR operation of two numbers.

  • Bitwise negation operator (~): used to perform a bitwise negation operation on a number.

  • Left shift operator (<<): used to shift the binary representation of a number to the left by a specified number of digits.

  • Right shift operator (>>): used to shift the binary representation of a number to the right by the specified number of digits.

  • 5. Assignment operator:

    • Simple assignment operator (=): used to convert the right operand The value is assigned to the left operand.

    • Addition assignment operator (=): used to perform addition operations and assign the result to the left operand.

    • Subtraction assignment operator (-=): used to perform a subtraction operation and assign the result to the left operand.

    • Multiplication assignment operator (*=): used to perform multiplication operations and assign the result to the left operand.

    • Division assignment operator (/=): used to perform division operations and assign the result to the left operand.

    • Remainder assignment operator (%=): used to perform the remainder operation and assign the result to the left operand.

    • Power assignment operator (**=): used to perform power operations and assign the result to the left operand.

    • Integer division assignment operator (//=): used to perform an integer division operation and assign the result to the left operand.

    In addition to the operators listed above, Python also provides some other operators, such as the membership operator (used to check whether a value belongs to a certain sequence), the identity operator ( Used to compare whether the memory addresses of two objects are the same), etc. However, these operators are relatively less frequently used. Operators in Python are divided into the following categories:

    1. Arithmetic operators:

    • Addition operator (): used to perform the addition operation of two numbers.

    • Subtraction operator (-): used to perform the subtraction operation of two numbers.

    • Multiplication operator (*): used to perform the multiplication operation of two numbers.

    • Division operator (/): used to perform the division operation of two numbers, and the result is a floating point number.

    • Integer division operator (//): used to perform an integer division operation between two numbers, and the result is an integer.

    • Remainder operator (%): used to calculate the remainder after dividing two numbers.

    • Power operator (**): used to perform exponential operations on a number.

    2. Comparison operator:

    • Equality operator (==): used to check whether two numbers are equal.

    • Inequality operator (!=): used to check whether two numbers are not equal.

    • Greater than operator (>): used to check whether the left operand is greater than the right operand.

    • Less than operator (<): used to check whether the left operand is less than the right operand.

    • Greater than or equal to operator (>=): used to check whether the left operand is greater than or equal to the right operand.

    • Less than or equal to operator (<=): used to check whether the left operand is less than or equal to the right operand.

    3. Logical operators:

    • And operator (and): used to check whether multiple conditions Satisfied at the same time.

    • Or operator (or): used to check whether at least one of multiple conditions is satisfied.

    • Non operator (not): used to reverse the result of a condition.

    4. Bitwise operators:

    • The bitwise AND operator (&): used to perform two Bitwise AND operations on numbers.

    • The bitwise OR operator (|): used to perform the bitwise OR operation of two numbers.

    • Bitwise XOR operator (^): used to perform bitwise XOR operation of two numbers.

    • Bitwise negation operator (~): used to perform a bitwise negation operation on a number.

    • Left shift operator (<<): used to shift the binary representation of a number to the left by a specified number of digits.

    • Right shift operator (>>): used to shift the binary representation of a number to the right by the specified number of digits.

    5. Assignment operator:

    • Simple assignment operator (=): used to convert the right operand The value is assigned to the left operand.

    • Addition assignment operator (=): used to perform addition operations and assign the result to the left operand.

    • Subtraction assignment operator (-=): used to perform a subtraction operation and assign the result to the left operand.

    • Multiplication assignment operator (*=): used to perform multiplication operations and assign the result to the left operand.

    • Division assignment operator (/=): used to perform division operations and assign the result to the left operand.

    • Remainder assignment operator (%=): used to perform the remainder operation and assign the result to the left operand.

    • Power assignment operator (**=): used to perform power operations and assign the result to the left operand.

    • Integer division assignment operator (//=): used to perform an integer division operation and assign the result to the left operand.

    In addition to the operators listed above, Python also provides some other operators, such as the membership operator (used to check whether a value belongs to a certain sequence), the identity operator ( Used to compare whether the memory addresses of two objects are the same), etc. These operators have different applications in different situations, and the appropriate operator can be selected according to specific needs to complete the corresponding operation.

    The above is the detailed content of What are the python operation symbols?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!