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

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!")
主站蜘蛛池模板: 安西县| 海城市| 临潭县| 新平| 乳源| 津市市| 清镇市| 墨竹工卡县| 华池县| 光泽县| 新宁县| 益阳市| 襄垣县| 搜索| 北京市| 大丰市| 友谊县| 宁津县| 昌黎县| 福建省| 黔东| 岢岚县| 延津县| 辽中县| 黔江区| 海淀区| 通化县| 祁阳县| 德安县| 博白县| 阳西县| 泌阳县| 博乐市| 宜春市| 溆浦县| 钦州市| 海南省| 黑水县| 蒙城县| 庆安县| 慈利县|