Skip to content

Instantly share code, notes, and snippets.

@devops-school
Last active July 24, 2022 12:13
Python Tutorials: Operators
# Arithmetic operators
x = 15
y = 4
# Output: x + y = 19
print('x + y =',x+y)
# Output: x - y = 11
print('x - y =',x-y)
# Output: x * y = 60
print('x * y =',x*y)
# Output: x / y = 3.75
print('x / y =',x/y)
# Output: x // y = 3
print('x // y =',x//y)
# Output: x ** y = 50625
print('x ** y =',x**y)
# This is a Python Demo - Operators
x = 6
y = 2
# addition
print(x + y) # 8
# subtraction
print(x - y) # 4
# multiplication
print(x * y) # 12
# division
print(x / y) # 3
# equal to
print(x == y) # False
# not equal to
print(x != y) # True
# less than
print(x < y) # False
# and
print(x > 0 and y < 0) # True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment