User Tools

Site Tools


products:ict:python:basic_arithmetic_comparison_and_assignment_operators

In Python, there are several basic arithmetic, comparison, and assignment operators that you can use.

Here's a brief overview of each:

Arithmetic Operators:

1. Addition: `+`

2. Subtraction: `-`

3. Multiplication: `*`

4. Division: `/`

5. Floor Division (integer division): `//`

6. Modulus (remainder): `%`

7. Exponentiation: `**`

Comparison Operators:

1. Equal to: `==`

2. Not equal to: `!=`

3. Greater than: `>`

4. Less than: `<`

5. Greater than or equal to: `>=`

6. Less than or equal to: `⇐`

Assignment Operators:

1. Assignment: `=`

2. Addition assignment: `+=`

3. Subtraction assignment: `-=`

4. Multiplication assignment: `*=`

5. Division assignment: `/=`

6. Floor division assignment: `//=`

7. Modulus assignment: `%=`

8. Exponentiation assignment: `**=`

Examples:

# Arithmetic Operators

a = 10

b = 3

print(a + b) # Addition

print(a - b) # Subtraction

print(a * b) # Multiplication

print(a / b) # Division

print(a // b) # Floor Division

print(a % b) # Modulus

print(a ** b) # Exponentiation

# Comparison Operators

x = 5

y = 10

print(x == y) # Equal to

print(x != y) # Not equal to

print(x > y) # Greater than

print(x < y) # Less than

print(x >= y) # Greater than or equal to

print(x ⇐ y) # Less than or equal to

# Assignment Operators

c = 5

c += 3 # Equivalent to c = c + 3

print©

d = 10

d -= 2 # Equivalent to d = d - 2

print(d)

e = 3

e *= 4 # Equivalent to e = e * 4

print(e)

f = 20

f /= 5 # Equivalent to f = f / 5

print(f)

g = 11

g = 3 # Equivalent to g = g 3

print(g)

h = 13

h %= 5 # Equivalent to h = h % 5

print(h)

i = 2

i **= 3 # Equivalent to i = i ** 3

print(i)

These operators are fundamental in Python programming and are used extensively in various programming tasks.

products/ict/python/basic_arithmetic_comparison_and_assignment_operators.txt · Last modified: 2024/03/01 19:06 by wikiadmin