I have typed ":!python" to launch python shell in vim, but I can't close it.
I have tried ^Z but it has no effect.
^D is what you are actually looking for.
Alternatively, you can use the expression exit() or quit().
How to exit from ":!python" in Vim?