Logical operators in python w3schools

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2022 by Refsnes Data. All Rights Reserved.
W3Schools is Powered by W3.CSS.

Python Operators

Operators are used to perform operations on variables and values.

In the example below, we use the + operator to add together two values:

Python divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Identity operators
  • Membership operators
  • Bitwise operators

Python Arithmetic Operators

Arithmetic operators are used with numeric values to perform common mathematical operations:

OperatorNameExampleTry it
+ Addition x + y Try it »
- Subtraction x - y Try it »
* Multiplication x * y Try it »
/ Division x / y Try it »
% Modulus x % y Try it »
** Exponentiation x ** y Try it »
// Floor division x // y Try it »

Python Assignment Operators

Assignment operators are used to assign values to variables:

OperatorExampleSame AsTry it
= x = 5 x = 5 Try it »
+= x += 3 x = x + 3 Try it »
-= x -= 3 x = x - 3 Try it »
*= x *= 3 x = x * 3 Try it »
/= x /= 3 x = x / 3 Try it »
%= x %= 3 x = x % 3 Try it »
//= x //= 3 x = x // 3 Try it »
**= x **= 3 x = x ** 3 Try it »
&= x &= 3 x = x & 3 Try it »
|= x |= 3 x = x | 3 Try it »
^= x ^= 3 x = x ^ 3 Try it »
>>= x >>= 3 x = x >> 3 Try it »

Chủ Đề