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

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!")
主站蜘蛛池模板: 开原市| 定结县| 济源市| 施秉县| 齐齐哈尔市| 安福县| 德庆县| 绥德县| 保德县| 珠海市| 小金县| 奇台县| 宝清县| 黄石市| 剑川县| 长武县| 乌苏市| 南川市| 水富县| 陇川县| 株洲县| 高唐县| 平顶山市| 南江县| 那坡县| 富锦市| 丹东市| 镇巴县| 南雄市| 海盐县| 根河市| 宕昌县| 南安市| 杨浦区| 太仆寺旗| 石泉县| 四会市| 偏关县| 洪江市| 阜城县| 江陵县|