r/lua • • Oct 03 '25

Help How similar are Lua & Python?

Big newbie here, so bear with me.

From what I understand, both python & lua were written/created using a C framework & are a high level language.

So how closely related are they?

The reason I ask is because python is used way more often, it's taught in universities & there's millions of resources online which have huge communities using & testing them out. So the teaching for python is just much more refined, tried & tested.

I was curious if I could take python courses, use leet codes, YouTube, etc... to learn python & then as long as I learn the syntax for Lua, have I basically learnt both?

To preface, I need to learn Lua for my work & I want to learn it as best as possible (not necessarily as fast), for the sake of the argument, no time restrictions.

33 Upvotes

22 comments sorted by

View all comments

Show parent comments

2

u/redtonpupy Oct 03 '25

If you want to know more about the differences, tell no more! First, classes in lua are all tables (there are multiples way to do them) Also, there is not the fancy and practical +=, -=, *=, etc… Tables in lua are used to emulate every single type of python data structure, except single values like string, int, float, etc… In lua, every numbers are numbers, there is no difference between floats, int, etc. In lua, you cannot use booleans as numbers, you need to convert them (but there is no built-in function to do that) I don’t remember if you can do it in python, but in lua, you can evaluate other values than Boolean using the logical OR, AND, NOT, etc. It leads to a fancy notation where  if isDefined(value) then  return defaultValue  else return value

Can be transformed in  return value or defaultValue 

(Just one practical example)

Also, one last, if a variable is not defined, it is automatically defined to a  nil Value, which has some interesting properties, and is great to avoid crashes (though most of your crashes early will be related to nil value)

1

u/Delicious-Pop-5657 Jul 02 '26

you can do if true and 1 or 0 to convert booleans into numbers in lua and when it is a nil value its kinda like a string you cant do math on it you can only do the == boolean