Search code examples
pythonsyntaxkeywordstatements

Making your own statements


Is there a way to define new statements like def, with, for of my own in Python? Of course, I don't mean to override the existing statements, only create some of my own.

If so, how do I do it? Can you point me to good docs on the subject?


Solution

  • No, you cannot add new syntax within a Python program. The only way to alter the language is to edit and recompile the grammar file and supporting C code, to obtain a new altered interpreter, compiler and runtime.