Suppose you want to create and run a short script. It’s often faster not to bother opening up a text editor. Instead, use shell history to write a file, then chmod and execute it:
$ cat > /tmp/me.py
#!/usr/bin/env python
print('hello world')
$ chmod a+x !$
chmod a+x /tmp/me.py
$ !$
/tmp/me.py
hello world
$