You can do this quite easily by adding a line to your
crontab file. Do this:
From your $ shell prompt, enter
man crontab. Read what it says. When you finish, dismiss the man page be entering
q, and then enter
crontab -e on the command line.
nano editor will start, and show you a "default" crontab in which each line is commented - it begins with "#". Using
nano, move the insertion point to the first new line at the end of the file. Enter this:
@reboot /usr/bin/python3 ~/somefolder/somefile.py &
Where ~/ is your home directory (probably /home/pi), "somefolder" is a folder in your home directory containing the Python script you want to run, and "somefile.py" is your Python script. The
& lets your Python script run "in the background", and doesn't hold things up.
After you've added this line, use
^O) to save the file, and accept whatever filename it suggests. Then exit
^X. You'll get a confirmation message that your crontab file has been updated.
Reboot your pi, and your Python script will execute; and it will execute each time your pi reboots.