HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Python: Print and RepeatVariablesData Types & NumbersStringsListsConditions (if / elif / else)Loops (for / while)FunctionsOperatorsDictionariesTuples & SetsError Handling (try / except)Classes (Object-Oriented)File OperationsComments & IndentationBooleans (True / False)Lambda & map / filterModules (import)InheritanceVariable Scope
REFERENCE
📖 Overview
🖥️ Output & Input
🔢 Numbers & Math
✍️ String
📋 List
🗂️ Dictionary & Set
🔁 Condition & Loop
🧩 Function
📁 File & Error
🔄 Type & Conversion
Python›Operators

Operators

Math (+ - * / % // **), comparison (== != < >) and logic (and or not) operators.

Simple enough for a 5-year-old to understand

Math operators

Besides the four basic operations, there's also remainder (%), floor division (//) and exponent (**).

Operations with numbers
1
print(7 + 3)
Addition: 10
CodeAddition: 10
2
print(7 - 3)
Subtraction: 4
CodeSubtraction: 4
3
print(7 * 3)
Multiplication: 21
CodeMultiplication: 21
4
print(7 / 2)
Division (always a float): 3.5
CodeDivision (always a float): 3.5
5
print(7 // 2)
Floor division (drop the decimal): 3
CodeFloor division (drop the decimal): 3
6
print(7 % 2)
Remainder (mod): 1
CodeRemainder (mod): 1
7
print(2 ** 3)
Exponent (2 to the power of 3): 8
CodeExponent (2 to the power of 3): 8
Code
💡 Hint: % (mod) is very commonly used to tell whether a number is even or odd: if sayi % 2 == 0 it's even.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.What is the result of 17 % 5?
2.Print the remainder of dividing 23 by 4.

🎯 Expected output: 3

Loading editor…

About this topic

Operators are symbols that perform operations on values. Alongside the four basic operations, Python also has special operators: floor division, remainder, and exponentiation. These come in handy much more often in everyday code than you might think—for example, you can tell if a number is odd or even using the remainder operator.

Operators do not only work with numbers. The plus sign joins two texts, glues two lists end-to-end; the asterisk repeats a text. Python knows what the same symbol means for each type, but it throws an error when you mix different types.

What you will learn

  • Arithmetic operators and order of operations
  • What floor division and remainder operators do
  • The exponentiation operator
  • Comparison operators
  • Shortcut assignment operators
  • Using plus and asterisk with texts and lists

When to use?

The remainder operator is used in odd-even checks, performing tasks every N steps, and wrapping a value into a specific range. Floor division comes in handy when dividing a total into pages or converting seconds into minutes.

Shortcut assignment operators are standard usage for counters and accumulating totals in loops.

Common mistakes

Wrong

print(10 / 3)

Normal division always returns a decimal result; here it yields 3.3333333333333335, not 3. If you want an integer result, you must use the floor division operator.

Correct

print(10 // 3)

Wrong

print(2 ^ 3)

The caret sign in Python is NOT exponentiation, it is a bitwise XOR operation; the result is 1, not 8. Double asterisks are used for exponentiation.

Correct

print(2 ** 3)

Wrong

print("Age: " + 30)

The plus sign cannot combine text with a number; you get "TypeError: can only concatenate str (not "int") to str". You need to convert the number to text or use an f-string.

Correct

age = 30
print(f"Age: {age}")

Frequently asked questions

What does the remainder operator do?

It gives the remainder from a division operation. Its most common use is checking for odd/even: if the remainder of a number divided by 2 is zero, the number is even. It is also used for periodic tasks, such as printing a report every tenth step in a loop.

How is the order of operations?

First exponentiation, then multiplication, division, floor division, and remainder, and lastly addition and subtraction. Those at the same level are evaluated from left to right. If there is a risk of confusion, use parentheses: it also makes it clearer for the reader.

Is there an increment operator in Python?

There is no operator in the form of plus plus; those coming from C and Java look for this. To increment a variable by one in Python, the shortcut assignment operator is used. Writing plus plus does not cause an error, but it does not do what you expect either.

Summary

Python operators work on texts and lists alongside numbers; floor division, remainder, and exponentiation operators are frequent tools in everyday code. The two most common confusions: normal division returning a decimal and the caret sign not being exponentiation.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code