Skip to content

Instantly share code, notes, and snippets.

@phalt
Created May 29, 2020 04:19
Show Gist options
  • Save phalt/7ca393e08e5398812a34d8f0b6667d76 to your computer and use it in GitHub Desktop.
Save phalt/7ca393e08e5398812a34d8f0b6667d76 to your computer and use it in GitHub Desktop.

Functions that print their own source code.

Python

x = ['print("x =", x)', 'for s in x: print(s)']
print("x =", x)
for s in x: print(s)

JS

function f() {console.log(f.toString() + "f();")}f();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment