- Lua Quick Start Guide
- Gabor Szauer
- 163字
- 2021-08-05 10:30:41
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!")
推薦閱讀
- 自然語言處理實戰(zhàn):預(yù)訓(xùn)練模型應(yīng)用及其產(chǎn)品化
- Learning Selenium Testing Tools with Python
- 數(shù)據(jù)結(jié)構(gòu)(Java語言描述)
- Learning Python Design Patterns(Second Edition)
- Java編程技術(shù)與項目實戰(zhàn)(第2版)
- Java程序設(shè)計
- Unity Game Development Scripting
- Mastering Apache Maven 3
- C語言程序設(shè)計教程
- Mastering openFrameworks:Creative Coding Demystified
- Go語言開發(fā)實戰(zhàn)(慕課版)
- 代碼閱讀
- Arduino電子設(shè)計實戰(zhàn)指南:零基礎(chǔ)篇
- Jakarta EE Cookbook
- 輕松學(xué)Scratch 3.0 少兒編程(全彩)