Expressions
Expressions compute Nilakan values. Operators are strict about operand types.
Syntax
Section titled “Syntax”total = 1 + 2 * 3label = "item-" + str(3)ok = total > 3 and total < 10result = "yes" if ok else "no"fallback = [1].get(10) catch 0first = [10, 20, 30][0]tail = [10, 20, 30][1:]Semantics
Section titled “Semantics”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 between different types is
False; inequality is True. 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 = 1end = 2all_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()Constraints And Errors
Section titled “Constraints And Errors”Mixed scalar equality such as 1 == "1" is False, including inside containers. 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.
Examples
Section titled “Examples”xs = [1, 2] + [3]ys = xs * 2print(ys)
left = {1, 2, 3}right = {2, 3, 4}print(left & right)