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

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:
主站蜘蛛池模板: 松滋市| 航空| 苗栗县| 昌平区| 黔西| 古蔺县| 嘉鱼县| 土默特左旗| 海门市| 洛扎县| 万年县| 阿克陶县| 孝昌县| 内江市| 澄城县| 通州区| 靖安县| 石渠县| 仁化县| 从江县| 清河县| 定日县| 河曲县| 金门县| 西峡县| 扶绥县| 田林县| 昌吉市| 肇州县| 朝阳县| 常山县| 鄂托克旗| 阿鲁科尔沁旗| 通城县| 滨海县| 闸北区| 大化| 阜康市| 东海县| 盘山县| 靖远县|