- Lua Quick Start Guide
- Gabor Szauer
- 128字
- 2021-08-05 10:30:37
Finding a type
There is one very important function built into Lua, type. This function will return the type of a variable as a string. Let's take a look at this function in action:
var1 = true
var2 = 3.145
var3 = nil
var4 = type(var1)
var5 = type(type(var2))
print (type(var1)) -- boolean
print (type(var2)) -- number
print (type(var3)) -- nil
print (var4) -- boolean
print (var5) -- string
Because the type function returns a string, the result can be assigned to a variable, like so:
var4 = type(var1)
Or, the result can be passed directly to a function such as print, like so:
print (type(var1))
The type of the type of something type(type(var2)), as represented by var5, will always be a string. This is because, as stated before, type returns a string.
推薦閱讀
- Learning Selenium Testing Tools with Python
- INSTANT FreeMarker Starter
- Scratch 3游戲與人工智能編程完全自學(xué)教程
- Java面向?qū)ο蟪绦蜷_發(fā)及實(shí)戰(zhàn)
- SQL基礎(chǔ)教程(第2版)
- 執(zhí)劍而舞:用代碼創(chuàng)作藝術(shù)
- HTML5從入門到精通(第4版)
- Java程序員面試筆試寶典(第2版)
- 零基礎(chǔ)學(xué)C語言第2版
- R數(shù)據(jù)科學(xué)實(shí)戰(zhàn):工具詳解與案例分析
- HTML5+CSS3+jQuery Mobile APP與移動(dòng)網(wǎng)站設(shè)計(jì)從入門到精通
- IBM Cognos TM1 Developer's Certification guide
- OpenCV Android Programming By Example
- Simulation for Data Science with R
- Java EE 8 and Angular