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

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:
主站蜘蛛池模板: 屯昌县| 金华市| 灯塔市| 镇平县| 乳山市| 太白县| 眉山市| 龙井市| 乌海市| 江口县| 栾城县| 呼伦贝尔市| 正镶白旗| 青川县| 双城市| 黔西县| 昂仁县| 南通市| 金秀| 利川市| 府谷县| 鄂尔多斯市| 五指山市| 子长县| 民勤县| 武邑县| 苏尼特右旗| 绩溪县| 吉水县| 余庆县| 邵阳市| 潮安县| 韶山市| 崇明县| 桐庐县| 商都县| 阿勒泰市| 达尔| 张家界市| 永修县| 保定市|