官术网_书友最值得收藏!

Python operators

An operator in Python is something that can carry out arithmetic or logical operations on an expression. The variable on which the operator operates is called the operand. Let's try to understand the various operators that are available in Python:

  • Arithmetic:
  • Assignment:
    • a = 0 evaluates to a=0
    • a +=1 evaluates to a = a + 1
    • a -= 1 evaluates to a = a + 1
    • a *= 2 evaluates to a = a * 2
    • a /= 5 evaluates to a = a / 5
    • a **= 3 evaluates to a = a ** 3
    • a //= 2 evaluates to a= a // 2 (floor division 2)
    • a %= 5 evaluates to a= a % 5
  • Logical operators:
    • and: True: If both the operands are true, then the condition becomes true. For example, (a and b) is true.
    • or: True: If any of the two operands are non-zero, then the condition becomes true. For example, (a or b) is true.
    • not: True: This is used to reverse the logical state of its operand. For example, not (a and b) is false.
  • Bitwise operators:
主站蜘蛛池模板: 临清市| 太和县| 侯马市| 齐齐哈尔市| 德钦县| 洮南市| 加查县| 泾阳县| 永新县| 延安市| 永新县| 胶南市| 沙湾县| 武陟县| 仪征市| 拜城县| 壤塘县| 荥经县| 乾安县| 天等县| 新田县| 清苑县| 嘉义市| 墨玉县| 松阳县| 乳源| 蒙山县| 康平县| 屏山县| 张家口市| 师宗县| 阿克苏市| 望奎县| 开封市| 屯昌县| 永吉县| 建昌县| 九龙城区| 合作市| 宁安市| 桐城市|