Operators in Python: Arithmetic, Comparison, and Logical

In Python, as in every programming language, there are various operators for manipulating numbers, logical values, and comparing objects. Arithmetic Operators The most familiar ones are the mathematical operators. Sum: + Subtraction: - Multiplication: * Division: / or // Exponentiation: ** Modulus: % Let’s see an example for each operator: print(10 + 3) # Addition: 13 print(10 - 3) # Subtraction: 7 print(10 * 3) # Multiplication: 30 print(10 / 3) # Division: 3.3333... print(10 // 3) # Floor Division: 3 print(10 ** 3) # Exponentiation: 1000 print(10 % 3) # Modulus: 1 Of these, the one worth a quick note is the // operator, also known as “Floor Division.” This operator simply rounds down the division result to the nearest integer. ...

October 26, 2024 · 2 min ·