Skip to content

Expressions

Expressions compute Nilakan values. Operators are strict about operand types.

total = 1 + 2 * 3
label = "item-" + str(3)
ok = total > 3 and total < 10
result = "yes" if ok else "no"
fallback = [1].get(10) catch 0
first = [10, 20, 30][0]
tail = [10, 20, 30][1:]

See Operators And Precedence for the exact precedence and associativity table.

Arithmetic operators are +, -, *, /, and % for numbers. Strings, lists, and tuples support + concatenation and * repetition with an integer. Sets support |, &, ^, and - for union, intersection, symmetric difference, and difference.

Comparison operators are ==, !=, <, <=, >, and >=. Equality requires same-typed operands. Containers compare structurally; dict equality is order-insensitive.

Boolean operators are not, and, and or. Their operands must be booleans. and and or short-circuit: and skips its right operand when the left operand is false, and or skips it when the left operand is true.

Other binary operators evaluate both operands before applying the operator. Conditional expressions evaluate the guard first and then only the selected branch.

try expr propagates a direct err within the current function. expr catch fallback evaluates fallback only for expr’s direct-error result. Raw indexing is fatal on a missing index or key; use the sequence and dictionary get methods for recoverable access. See Error Handling.

Membership uses in and not in.

print("p" in "nilakan")
print(2 in [1, 2, 3])
print("name" in {"name": "Nilakan"})

Indexing reads strings, lists, tuples, and dicts. Slicing reads strings, lists, and tuples.

word = "nilakan"
print(word[0])
print(word[1:])

Supported slice shapes are:

xs = [10, 20, 30]
start = 1
end = 2
all_items = xs[:]
from_start = xs[:end]
to_end = xs[start:]
middle = xs[start:end]

Negative indexes and slice bounds are normalized from the end. Slice bounds are clamped into the valid range.

Function calls and member calls are expressions.

value = len([1, 2])
upper = "nilakan".upper()

Mixed scalar equality such as 1 == "1" is an error. String membership requires a string left operand. Dict indexing fails when the key is absent. Slices accept only start and end bounds; step slices are not implemented.

xs = [1, 2] + [3]
ys = xs * 2
print(ys)
left = {1, 2, 3}
right = {2, 3, 4}
print(left & right)