Arithmetic Operators

Post Reply
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Arithmetic Operators

Post by admin »

# Addition

Code: Select all

# Addition
result_add = 10 + 5  # Result: 15
# Subtraction

Code: Select all

# Subtraction[/size]
result_subtract = 20 - 8  # Result: 12
# Multiplication

Code: Select all

# Multiplication
result_multiply = 7 * 4  # Result: 28
# Division

Code: Select all

# Division
result_divide = 15 / 3  # Result: 5.0 (float division)
# Floor Division

Code: Select all

# Floor Division
result_floor_divide = 15 // 4  # Result: 3 (integer division)
# Modulus (Remainder)

Code: Select all

# Modulus (Remainder)
result_modulus = 20 % 3  # Result: 2
# Equal to

Code: Select all

# Equal to
is_equal = (5 == 5)  # Result: True
# Not equal to

Code: Select all

# Not equal to
not_equal = (10 != 5)  # Result: True
# Greater than

Code: Select all

# Greater than
greater_than = (15 > 10)  # Result: True
# Less than

Code: Select all

# Less than
less_than = (8 < 12)  # Result: True
# Greater than or equal to

Code: Select all

# Greater than or equal to
greater_than_equal = (20 >= 20)  # Result: True
# Less than or equal to

Code: Select all

# Less than or equal to
less_than_equal = (7 <= 9)  # Result: True
# Logical AND

Code: Select all

# Logical AND
logical_and = (True and False)  # Result: False
# Logical OR

Code: Select all

# Logical OR
logical_or = (True or False)  # Result: True
# Logical NOT

Code: Select all

# Logical NOT
logical_not = not True  # Result: False
# Assignment

Code: Select all

# Assignment
x = 10
# Increment

Code: Select all

# Increment
x += 5  # Equivalent to x = x + 5
# Decrement

Code: Select all

# Decrement
x -= 3  # Equivalent to x = x - 3
# Multiplication assignment

Code: Select all

# Multiplication assignment
x *= 2  # Equivalent to x = x * 2
# Assignment

Code: Select all

# Assignment
x = 10
# Increment

Code: Select all

# Increment
x += 5  # Equivalent to x = x + 5
# Decrement

Code: Select all

# Decrement
x -= 3  # Equivalent to x = x - 3
# Multiplication assignment

Code: Select all

# Multiplication assignment
x *= 2  # Equivalent to x = x * 2
Post Reply