While you will definitely want an event loop driven solution for your game as @LuigiBro provided, there are some other ways to be able to run your code without it exiting immediately, that you should be aware of.
The first and easiest is to run python interactively at a command prompt, or equivalently in a python console if your IDE provides one. There you can just type the commands one by one and see what happens with everything waiting for you to run the next command. For example, here is a screen capture from my terminal.
Both of these are useful even if you aren't using pygame.
$ python3
>>> import pygame
pygame 2.1.2 (SDL 2.0.20, Python 3.10.12)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> pygame.init()
(5, 0)
>>> prozor = pygame.display.set_mode((200, 200))
>>>
At this point I have a 200x200 pygame window open on my desktop awaiting my next python command.
If you really want or need to be running from a script (and you haven't started code that captures your keyboard input), you can add
x = input()
to the end of your script. This will block until you hit the Enter key.
Both of these will be useful even if you aren't using pygame.