Auto press key

I want to make the bot to press a key number “4” is there a way to make it work? this is an example in phyton with a script what i would like to do.