Coming from Python
Side-by-side comparisons for Python developers.
Variables
python
# Python
name = "Alice"
age = 30
PI = 3.14wyn
// Wyn
var name = "Alice"
var age = 30
const PI = 3.14Functions
python
# Python
def greet(name: str) -> str:
return f"Hello, {name}!"wyn
// Wyn
fn greet(name: string) -> string {
return "Hello, ${name}!"
}Loops
python
# Python
for i in range(10):
print(i)
for name in ["Alice", "Bob"]:
print(name)wyn
// Wyn
for i in 0..10 {
println("${i}")
}
for name in ["Alice", "Bob"] {
println(name)
}Conditionals
python
# Python
if x > 0:
print("positive")
elif x == 0:
print("zero")
else:
print("negative")wyn
// Wyn
if x > 0 {
println("positive")
} else if x == 0 {
println("zero")
} else {
println("negative")
}Pattern Matching
python
# Python 3.10+
match command:
case "quit":
exit()
case "hello":
print("Hi!")
case _:
print("Unknown")wyn
// Wyn
match command {
"quit" => System.exit(0)
"hello" => println("Hi!")
_ => println("Unknown")
}Structs (Classes)
python
# Python
class Point:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
def distance(self, other: "Point") -> float:
return ((other.x - self.x)**2 + (other.y - self.y)**2)**0.5wyn
// Wyn
struct Point {
x: int
y: int
fn distance(self, other: Point) -> float {
var dx = (other.x - self.x) * (other.x - self.x)
var dy = (other.y - self.y) * (other.y - self.y)
return Math.sqrt(dx + dy)
}
}Concurrency
python
# Python (asyncio)
import asyncio
async def fetch(url):
# ...
return data
async def main():
results = await asyncio.gather(
fetch("url1"),
fetch("url2"),
)wyn
// Wyn (green threads)
fn fetch(url: string) -> string {
return Http.get(url)
}
var f1 = spawn fetch("url1")
var f2 = spawn fetch("url2")
var r1 = await f1
var r2 = await f2Key Differences
| Feature | Python | Wyn |
|---|---|---|
| Typing | Dynamic | Static |
| Compilation | Interpreted | Compiled to native |
| Concurrency | asyncio/GIL | Green threads (M:N) |
| Memory | GC | Arena allocator |
| Binary size | ~50MB (with runtime) | ~32KB |
| Startup | ~30ms | <1ms |