The "Automation > Scripting" console is a place you can run some script immediately. You can use it to test a line at a time when developing your own script, or just paste your entire script and run it immediately. You can also turn on recording to easily build a basic script. And you have the Intellisense popup as you type python objects to see the properties and methods beneath it. Think of it as a test bed for developing a script, but you can also run your entire debugged script there.
The "python code" does not immediately run. It is triggered by its placement in the Outline, and the callback you set. You can also use the Property Provider to create custom fields in the Details. This allows you to create something that appears like a custom load or result or other custom Outline object depending on its placement in the Outline. Closely related is the "Python Result" which can display custom result contours on the model. See documentation (https://ansyshelp.ansys.com):
go to "Mechanical Application > Mechanical User's Guide > Python Code"
Also, "Mechanical Application > Scripting in Mechanical Guide > Scripting Examples > Examples Using the Python Code Object"
and "Mechanical Application > Mechanical Users' Guide > Results > Python Result"
See Forum post:
https://discuss.ansys.com/discussion/1177/how-to-use-pythoncode-object-in-mechanical-2021r2
https://developer.ansys.com/blog/script-tip-friday-python-code-object-mechanical