Lua运算符

Lua基础练习

print("\n======session 1======\n")
print(1+2)
print(5/10)
print(0.5/10.0)
print(2^10)

local num = 1357
print(num % 2)
print(num % 2 == 0)
print(num % 2 == 1)

print("\n======session 2======\n")

print(1<2)
print(1>2)
print(1~=2)
print(true == false)
print(true ~= true)

print("\n======session 3======\n")

local x = {a = 1, b = 2}
local y = {a = 1, b = 2}

if x == y then
    print("x == y")
else
    print("x ~= y")
end

print("\n======session 4======\n")

local a = nil
local b = 0
local c = 100

print(a and b)
print(a and c)
print(b and c)
print(a or b)
print(a or c)
print(not a)
print(not b)

print("\n======session 5======\n")

print("hello" .. "world")
print(1 .. 0)

print(string.format("%s-%s", "hello", "world"))
print(string.format("%d-%s-%.2f", 100, "hello", 1.22))

print("\n======session 6======\n")

local a, b = 1, 2
local x, y = 3, 4
local i = 10
local res = 0

print(a + i < b/2 + 1)
print(b + y^5*2)
print(a < y and b < x)