![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Advertisements