What colin said, or (in every terminal emulator I've used), ctrl-d to send end of file, which will close it.
$ python
>>> while True:
... pass
...
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt