Why won't this work?

def Test_method():
    def Test1():
        print("Hello")
    
        def Test2():
            print("There")
    
    Test1()
    Test2()

It’s not clear what you are trying to do; it is possible, but rarely done, to run functions from within functions. There is almost certainly a better way to accomplish your purpose. In Python, moreover, we do not begin function names with uppercase letters.

That said, it doesn’t work because:

  1. There is no call to Test_method()

  2. Test2() is in the namespace of Test1(). It cannot be directly accessed from Test_method(). Test2() must be called from within a namespace where it can be seen.

def Test_method():
    def Test1():
        print("Hello")
    
        def Test2():
            print("There")
            
        Test2()  # call from within Test1()
    
    Test1()
    #Test2()
    
Test_method()

Output::

Hello
There

Yes! Thank You! This is what I came up with after some consideration…

def test_method(t1, t2):
    first = t1
    second = t2
    return first, second
    
t1, t2 = test_method("Hello", "There")
print(t1 + " " + t2)
1 Like

Sooo much better! :slightly_smiling_face: Pythonic, even!