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

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:
主站蜘蛛池模板: 区。| 铜山县| 桃园县| 崇左市| 若羌县| 象山县| 平邑县| 金湖县| 平邑县| 寿光市| 利辛县| 东港市| 广德县| 洮南市| 秦皇岛市| 乐都县| 通江县| 冷水江市| 南汇区| 肇州县| 文化| 连平县| 盐城市| 个旧市| 瑞金市| 治多县| 商水县| 德令哈市| 全椒县| 萨嘎县| 孝义市| 日喀则市| 惠安县| 岗巴县| 鸡西市| 利川市| 阳曲县| 哈尔滨市| 松阳县| 湟中县| 淮南市|