This applies to Linux and MacOS and will make the script accessible to all users on the system
This is a relatively easy task to accomplish.
Take your Python script, e.g.
message = "Hello World!"
print(message)
Then add a "shebang" line to it so that Bash (or your chosen shell) knows how to interpret/execute the code
#! /usr/bin/env python
If your distribution uses "python3" then you will need to change 'python' to read 'python3', assuming you are wanting to use a Python 3 script e.g.
#! /usr/bin/env python3
Next, move the file to the /usr/local/bin
directory without the .py extension, and ensure that the script is executable,
sudo chmod a+x /usr/local/bin/helloworld
Now you should be able to execute the python script as if it were an ordinary bin file:
user@machine:~$ helloworld
Hello World!