Most of Python carries over: dynamic types, closures, generators, exceptions, iteration over a container, and classes whose methods receive the instance. The syntax changes. Blocks use braces, indentation has no meaning, a statement ends at the end of the line, and every name is declared before it is read.
Two differences change what a program does without an error message: // is a comment, and "", [] and {} are true. Read the traps even if you skip the tables.
// is a comment.let half = total // 2 keeps total and drops the rest of the line. There is no floor division operator, because / on two integers already truncates.
It truncates, it does not floor.-7 / 2 is -3 where Python gives -4, and -7 % 3 is -1 where Python gives 2. The sign follows the left side, as in C.
Only null, false, 0 and 0.0 are false."", [] and {} are all true, so if (!items) never fires. Test items.len() == 0.
in tests for a key. The keys of an array are its indices, so 2 in [10, 20, 30] is true and 99 in [10, 20, 30] is false. Use contains to search for a value.
s[0] is a number. Indexing a string gives the character code, 97 for "a". There is no character type.
clone is an operator, not a function.clone(a).append(9) parses as clone (a.append(9)), which appends to a. Write (clone a).append(9).
A container in a class body is one object for every instance, like a mutable class attribute in Python. Declare the slot as null and fill it in the constructor.
A default parameter value is built once, so a mutable default is shared between calls. Python has the same trap, for the same reason.
1 / 0 throws. Arithmetic never gives inf or a quiet nan.
1 < x < 3 is not a chained comparison. It compares (1 < x) with 3, and a bool against a number throws.
examples/pages/coming-from/python.nut
// // starts a comment, so a floor division quietly loses its right sidelet half = 7// 2
println(half)
// two integers divide as integers, and neither / nor % is floored
println(7 / 2)
println(-7 / 2)
println(-7 % 3)
// only null, false, 0 and 0.0 are false
println([] ? "[] is true" : "[] is false")
println("" ? "empty string is true" : "empty string is false")
// in asks about a key, and the keys of an array are its indices
println(2in [10, 20, 30])
println(99in [10, 20, 30])
println([10, 20, 30].contains(20))
Output:
7
3
-3
-1
[] is true
empty string is true
true
false
true