The class object is created when your script is run. That means any code inside the class will be executed just like it would be if it were outside the class (in the global scope). In order to create your class object, the interpreter needs to run over all of the code inside (which is why your "This will be run"
string is printed). The string inside your method definition is not run because...well... it's inside a method and it was not called.
The object has to be created before you reference it, so the code in the body has to be run at some point. The only sensible time to run it is when the class is created.
class Test:
print("Anything here will be run when 'Test' is first created.")
print("Note: This isn't run when an *instance* is created.")
print("Only when the class object is created")
def test_method(self):
print("test_method is never called so you won't see this.")
print(Test) # This will show something because the Test class object has been created.
Output:
Anything here will be run when 'Test' is first created.
Note: This isn't run when an *instance* is created.
Only when the class object is created
<class '__main__.Test'>