| Toit | Python |
| Current object | this | self |
| Single line comments | // | # |
| Logical 'and', 'or' and 'not' operators | and or not | and or not |
| Shift left, right, unsigned right | << >> >>> | << >> (no unsigned shift) |
| Integer division | / (on integer types) | // |
| Integer sizes | 64 | (arbitrary) |
| Statement grouping | (indent) | (indent) |
| Define a class Foo that inherits from Bar | class Foo extends Bar: | class Foo(Bar): |
| Define constructor for class Foo | constructor x: | def __init__(self, x): |
| Define constructor for class Foo that calls constructor of superclass Bar | constructor x: super x | def __init__(self, x): super(Bar, self).__init__(x) |
| Constructor that assigns to fields | constructor .x: | def __init__(self, x): self.x = x |
| Check object has type | bar is Foo | isinstance(bar, Foo) |
| Check object does not have type | bar is not Foo | not isinstance(bar, Foo) |
| Call a method foo with two arguments | foo x y | foo(x, y) |
| Declare a member variable in a class | x := null x := ? x/int := 0 x/int := ? | self.x = null |
| Declare a local variable in a method | x := null x := ? x/int := 0 x/int := ? | x = null |
| Define a constant | X ::= 0 | |
| Define a constant in a class | static X ::= 0 | |
| Define a top-level function | foo x y: | def foo(x, y): |
| Define an instance method in a class | foo x y: | def foo(self, x, y): |
| Define a static method in a class | static foo x y | |
| If statement | if condition: | if condition: |
| Fixed loop | end.repeat: | i | | for i in range(end): |
| Three-part for loop | for i := 0; i < end; i++: | |
| Iterate over collection | collection.do: | x | | for x in collection: |
| While loop | while condition: | while condition: |
| Import local from library | import .library | |
| Import from library | import library | import library |
| Import into current namespace | import library show * | from library import * |
| Print/log | print "Hello" | print("Hello") |
| Print with interpolation | print "Hello $name" | print("Hello %s" %(name)) |
| Interpolate with padding | print "Hello $(%9s name)" | print("Hello %9s", %(name)) |