Lesson 08 of 55
8 mins readPython Relational Operators & Inequality (~=)
In Plain English
Lua uses standard comparison operators, with one notable unique syntax: inequality is written as `~=` (tilde equal), not `!=`.
Deep Dive: How It Works
Inequality (~=): In Lua, "not equal" is written as `~=`.
Equality (==): Compares numbers/strings by value, and tables/functions by memory reference identity.
Type Differences: Comparing values of different types with `==` returns `false` without implicit coercion.
Core Rules to Remember

~= for Not-Equal: Remember `~=` instead of `!=`.

Table Identity: Two distinct tables `{}` are not equal even if their contents are identical.
Live Interactive Example
Hit Run Code to see it liveTesting Equality and Inequality
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output Console
Click "Run Code" to view the rendered output.
How it works: ~= verified inequality, string comparison checked content, and table comparison checked reference.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Use ~= Inequality Operator
Declare `local code = 404`.
If `code ~= 200`, print `"Error status: " .. code`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.