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

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!")
主站蜘蛛池模板: 当雄县| 广饶县| 苍溪县| 德保县| 周至县| 东兰县| 南充市| 东明县| 双城市| 华亭县| 兴海县| 云梦县| 滁州市| 灯塔市| 霸州市| 若羌县| 景德镇市| 东安县| 菏泽市| 九龙坡区| 常德市| 库尔勒市| 泗水县| 和龙市| 林州市| 同德县| 秀山| 永嘉县| 巴南区| 海原县| 博湖县| 沽源县| 渭南市| 富平县| 峨眉山市| 崇信县| 福泉市| 长寿区| 奉新县| 上犹县| 资溪县|