Lua type()
Published Oct 18, 2023
Contribute to Docs
The type() method takes an argument and returns a value corresponding to the type of that argument in the following manner:
- If the value of the argument is an integer,
"integer"will be returned. - If the value of the argument is a float,
"float"will be returned. - For all other values,
nilwill be returned.
Syntax
The syntax of type() is as follows:
math.type(arg)
Where arg is the argument to be checked for its type.
Examples
The following examples illustrate the behavior of type():
print(math.type(5))print(math.type(6.3))print(math.type(-9))print(math.type("fugazzi"))
This results in the output:
integerfloatintegernil
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Lua on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
- Beginner Friendly.4 hours