Variables और Assignment
एक variable एक नाम है जो एक value holds करता है, और आप किसी भी समय यह बदल सकते हैं कि यह क्या holds करता है।
In this page:
Variables और Assignment
एक single equals sign से assign करें। Variables का कोई declared type नहीं होता, सिर्फ values का होता है, इसलिए same variable एक number hold कर सकता है और बाद में एक string। Lua multiple assignment support करता है, इसलिए a, b = b, a बिना किसी temporary के दो values swap करता है।
Note:
Names case sensitive हैं और इनमें letters, digits, और underscores हो सकते हैं लेकिन एक digit से शुरू नहीं हो सकते।
उदाहरण: Variables and assignment
local x = 10
x = "now a string"
print(x)
local a, b = 1, 2
a, b = b, a
print(a, b)
local p, q, r = 1, 2
print(p, q, r)
-- Output:
-- now a string
-- 2 1
-- 1 2 nil
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- end या function जैसा एक reserved word नाम की तरह इस्तेमाल करना
- यह उम्मीद करना कि एक declared type enforce होगा
- यह मान लेना कि a, b = 1 b को value 1 देता है
चैप्टर सारांश
- = से assign करें
- Variables किसी भी type की value hold कर सकते हैं
- Multiple assignment values swap करता है
- Missing values nil बन जाती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: