I'm a Python developer. What are the key differences I need to know for EK9?
← Getting Started · Ref: Q1006
Key differences for Python developers:
DECLARATION: Python 'x = 5' does both. EK9 separates: 'x <- 5' (create), 'x := 5' (update).
RETURN: Python 'return value'. EK9 has no return — declare '<- rtn as Type' in the signature.
NONE/NULL: Python 'if x is not None'. EK9 has no None — use 'if x?' (suffix ?) or guard 'if x <- expr()'.
LIST COMPREHENSION: Python '[x*2 for x in items if x > 0]'. EK9 uses stream pipeline: 'cat items | filter by isPositive | map with doubleIt | collect as List of Integer'.
INDENTATION: Both use indentation. EK9 uses 2 spaces per level.
TYPING: Python is dynamic. EK9 is statically typed with type inference (x <- 5 infers Integer).
BREAK/CONTINUE: Python has them. EK9 does not — use stream pipelines with head (replaces break) and filter (replaces continue).
WALRUS := Python's := is an expression (assigns AND evaluates). EK9's := is a statement (assigns only, cannot use in conditions). Use <- guard for Python's walrus pattern.
Example
defines module qa.gettingstarted.frompython defines function doubleValue() as pure -> number as Integer <- rtn as Integer: number * 2 isPositive() as pure -> number as Integer <- rtn as Boolean? zeroThreshold <- 0 rtn: number > zeroThreshold defines program FromPythonDemo() stdout <- Stdout() // Python: x = 5 → EK9: x <- 5 (declare), x := 10 (update) score <- 5 score := 10 stdout.println(`Score: ${score}`) // Python: return x*2 → EK9: <- rtn as Integer: number * 2 doubled <- doubleValue(21) stdout.println(`Doubled: ${doubled}`) // Python: [x*2 for x in items if x > 0] → EK9: stream pipeline numbers <- [-3, 5, -1, 8, 2, -4, 7] positiveDoubled <- cat numbers | filter by isPositive | map with doubleValue | collect as List of Integer stdout.println(`Result: ${positiveDoubled}`)
Common mistakes
E01072 — 'return' does not exist in EK9. Declare the return variable with '<- rtn as Type: expression' in the function signature.
Incorrect:
return number * 2
Correct:
<- rtn as Integer: number * 2
Other ways to ask this
- How do I transition from Python to EK9?
- What will surprise a Python developer about EK9?
- Python to EK9 — what changes?
Coming from another language?
Python developers: EK9 uses indentation like Python but is statically typed. The biggest adjustment is no return statement and no None.
Keywords: none, differences, walrus, return, python, migration, comprehension