In my app, you cannot try out the code. You can step through the execution to see how the program state changes, but that's based on a pre-generated trace of the program execution.
In Pythonista and 'Python for iOS' mentioned by ldayley you can execute the code you write. Don't know how they do it, though.