There are many ways to do this sort of thing.
You could echo a command and character string through ssh to the other pi.
You could set up a client/server arrangement using the "sockets" network interface, so one program listens to a port on one Pi and another one connects to that port and sends a message.
raspi1 has IP 192.168.1.31. It has a python program that listens on socket number 31415 for recognised messages.
raspi2 has IP 192.168.1.32. It has a python program that does stuff, and opens a connection to socket 31415 on 192.168.1.31 (or "raspi1"), sends a message and closes the socket. You can also make it wait for a response.
I chose 31415 as an example, as it isn't in the "privileged" range of sockets (0-1023), like 22 for ssh, 80 for www etc.
I can think of a few other methods, like use a serial connection (either USB adaptor, or cross-connect the UARTs on P1. Even connect a GPIO or two and implement your own simple serial port, or even (silly suggestion) in morse code
I can't give you example code, as I don't use Python, but a quick go with a search engine on "python simple socket client server" should throw up some results. It doesn't matter that most examples you find won't be for the Pi, networking is fairly standard on all Linux systems.