Hello, Python v2
Programs are plain .pyv2 files. print() accepts any number of values.
print("Hello, World!", 2 + 2)
THE PYTHON V2 + PYHOPE FIELD GUIDE
Not marketing fluff—50 compact, useful topics from your first print to closures, editor setup, CC0 sprites, DDA ray casting and a 9.4-million-pixel GPU frame.
Programs are plain .pyv2 files. print() accepts any number of values.
print("Hello, World!", 2 + 2)
Use the module command from the repository, or the pyv2 command after installing.
python3 -m pyv2 hello.pyv2
A # comment runs to the end of the line and is ignored by the interpreter.
# explain why, not what
answer = 42
Assignment creates a binding in the nearest function scope. No var keyword needed.
name = "Comet"
score = 10
Integers and decimals share one number type and print cleanly.
print(1, 2.5, 1e-3)
Use + - * / // % and **. Floor division and modulo follow Python rules.
print(10 / 4, 10 // 4, 7 % 3, 2 ** 8)
Single or double quotes work. Escape special characters with a backslash.
title = "Python v2"
print(title.upper())
Prefix a string with f and place any expression inside braces.
name = "Ada"
print(f"Hello, {name}: {2 ** 8}")
The boolean literals are true and false, always lowercase.
ready = true
print(ready and not false)
nil is the deliberate nothing value. Safe map lookups return it when no default is given.
missing = nil
print(type(missing))
Zero, empty strings, empty lists, empty maps, false and nil are falsey.
if []: print("no") else: print("empty") end
Open a block with a colon and close it with end. Indentation is for humans.
if score > 5:
print("high")
end
Chain choices without nesting another if.
if n < 0: print("negative")
elif n == 0: print("zero")
else: print("positive") end
Python v2 puts the question first: condition ? yes : no.
label = score >= 60 ? "pass" : "retry"
Repeat while a condition remains truthy.
n = 3
while n > 0: print(n) n -= 1 end
break exits the nearest loop immediately.
while true:
break
end
continue skips the rest of this iteration and moves to the next.
for n in range(5):
if n % 2 == 0: continue end
print(n)
end
for works with lists, strings, maps, and lazy ranges.
for name in ["Ada", "Grace"]: print(name) end
range(stop), range(start, stop), and range(start, stop, step) are lazy.
for i in range(10, 0, -2): print(i) end
Strings iterate Unicode characters instead of bytes.
for ch in "snake": print(ch) end
Lists can contain any mixture of values and allow negative indexing.
items = [1, "two", true]
print(items[-1])
push appends and returns the list; pop removes and returns the last value.
xs = [1, 2]
xs.push(3)
print(xs.pop(), xs)
slice(start, end) makes a new string or list and supports negative positions.
print([0, 1, 2, 3].slice(1, 3))
Sort, total, number, pair, or truth-test iterable values with concise builtins.
print([3, 1, 2].sort())
print(sum(range(5)))
print(enumerate(["a", "b"], 1))
print(zip([1, 2], ["a", "b"]))
Bare identifier keys become strings; quoted and computed keys work too.
hero = {name: "Ada", hp: 100}
Read and write map keys with dots when the key is a valid identifier.
hero.city = "London"
print(hero.name, hero.city)
get(key, default) avoids an error when optional data is absent.
print(hero.get("armor", 0))
Use fn, parameters in parentheses, a colon, and end.
fn add(a, b):
return a + b
end
return leaves the function immediately; no value means nil.
fn sign(n):
if n < 0: return -1 end
return 1
end
Inner functions remember outer variables and assignment updates the existing binding.
fn counter():
n = 0
fn bump(): n += 1 return n end
return bump
end
A function can call itself. Base cases prevent infinite recursion.
fn fib(n):
if n < 2: return n end
return fib(n-1) + fib(n-2)
end
fn can be an expression, so callbacks stay compact.
square = fn(x): return x * x end
print(square(7))
Strings include upper, lower, title, trim, replace, contains, slice, and more.
print(" comet ".trim().title())
Turn text into a list with split, then assemble it with list.join.
print("a,b,c".split(",").join(" - "))
Use str, int, float, bool, repr, and type. Invalid numeric text raises ValueError.
print(int("42"), float("2.5"), type(true))
assert is a normal function and accepts your own message.
assert(len([1, 2]) == 2, "list size changed")
Catch runtime failures as maps with kind, message, line, and trace; finally always runs.
try: raise "stop"
catch error: print(error.kind, error.message)
finally: print("clean")
end
Run pyv2 with no file for an interactive prompt; Ctrl-D exits.
python3 -m pyv2
Create, validate, and package production apps; pass arguments after the source filename.
pyv2 new windows-app "My App"
pyv2 check My-App
pyv2 build My-App
The repository includes run/test tasks, file association, highlighting, and snippets.
Ctrl+Shift+B # run current .pyv2 file
Choose Reopen in Container or create a Codespace; tests run after creation.
.devcontainer/devcontainer.json
The Playground builds responsive portfolios. The desktop app adds safe files, assets, editors, and Website, Game, CLI, or Windows EXE-ready project creation.
pyhope --studio
# New Project → Windows app
Immutable vectors provide addition, scaling, length, normalization, and dot products.
direction = Vec2(3, 4).normalized()
Text rows become collision worlds. Dots and spaces are open; other tiles are solid.
world = TileMap.from_text("###\n#.#\n###")
A sprite has a name, position, glyph, velocity, tags, and alive state.
hero = Sprite("hero", Vec2(1.5, 1.5), "@")
Systems run before sprite movement each tick, making logic deterministic and testable.
@engine.system
def gravity(scene, dt): ...
raycast walks the grid and reports the tile, distance, hit side, point, and step count.
hit = raycast(world, origin, direction)
The original Comet Kid, Byte Beast, Null Slime, blaster, and coin are public domain.
assets/sprites/LICENSE.md
WebGL2 live mode is 720p; benchmark mode ray-casts 4096×2304 = 9,437,184 pixels.
games.html#gpu
Run tests, validate app metadata, create an integrity-tracked kit, then build the real EXE on Windows or publish games with GitHub Pages.
pyv2 check My-App
pyv2 build My-App --native
VIDEO TUTORIAL AT 1,000 SUBSCRIBERS
Subscribe to Cube Comet. The complete Python v2 + PyHope install video releases when the channel reaches 1K.