官术网_书友最值得收藏!

Misc operators

The miscellaneous operators presented here do not fit into any of the previous groups. These operators are Lua constructs.

The assignment operator (=) changes the value of a variable. This operator has been used many times up until this point. The assignment operator allows for multiple assignment. All of the following are valid:

x = 2
y, z = 4, "hello"

The string concatenation operator (..) will combine two strings into a single string. This operator was covered in the String types section of this chapter. As a reminder, the syntax is:

hello = "hello,"
world = " world"
print (hello .. world)

Finally, the length operator (#) is a unary operator that will return the length of a string or a table. The use of this operator for strings has already been covered. The syntax of this operator is as follows:

print ("Enter a word: ")
word = io.read();
print (word .. " has " .. #word .. " letters!")
主站蜘蛛池模板: 高邑县| 西青区| 盐亭县| 出国| 诸暨市| 兰考县| 苍山县| 宝清县| 松江区| 伊春市| 广宁县| 应城市| 金华市| 柳河县| 镇原县| 涪陵区| 石首市| 定襄县| 宣汉县| 内黄县| 临夏市| 磐石市| 武冈市| 松桃| 红原县| 宁远县| 赞皇县| 通化县| 永兴县| 盐边县| 墨江| 通榆县| 缙云县| 大英县| 隆昌县| 三亚市| 鄂伦春自治旗| 通渭县| 嘉峪关市| 大宁县| 新密市|