- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does # mean in Lua programming?
The unary operator # is known as the Length operator in Lua. It is used almost everywhere in Lua. By everywhere, I meant that anywhere we would require to calculate the length of the any string or can also be used in tables also, but when it comes to table, it is generally not preferred to use the # operator as it doesn’t calculate the number of elements present inside the table.
Let’s explore different examples of the length operator to understand how we can make use of it.
Example
Consider the example shown below −
print(#"abcdefg") print(#{"a", "b", "c", 77})
Output
7 4
In the above example, the length operators work perfectly fine but when it comes to the table elements, it doesn’t work as expected.
Example
Consider the example shown below −
print(#{["a"]=1, ["b"]=9})
Output
0
- Related Articles
- What does operator ~= mean in Lua?
- How does Garbage Collection work in Lua Programming?
- What are Closures in Lua Programming?
- Comments in Lua Programming
- table.pack() function in Lua programming
- table.unpack() function in Lua programming
- Lexical Conventions in Lua Programming
- math.ceil() function in Lua programming
- math.floor() function in Lua programming
- math.max() function in Lua programming
- math.modf() function in Lua programming
- select() function in Lua programming
- Semicolon Conventions in Lua Programming
- Sort function in Lua programming
- string.byte() function in Lua programming

Advertisements