I am working with certain codes in python and I wanted to know if a certain value of a variable can be accesssed outside the function without explicitly declaring it a global variable.
for example:

I was using this:

    def func1():
        v1 = "value1"
        return v1
        print ("This is the first function")
    
    def func2():
        v2 = "value2"
        func1()
        print ("This is the second function")
    
    fo = input ("Enter 1/2\n")
    if fo == '1':
        func1()
    elif fo == '2':
        func2()
    else:
        print ("invalid")
    print (v1)

It results me this error:

        print (v1)
    NameError: name 'v1' is not defined

Can I use this value of `'v1'` variable outside the function without defining it to b `'global'`?? 
You have two options (actually more but lets keep it with two)

As Devon Ryan suggest and also my preference:

    def func1():
        v1 = "value1"
        print ("This is the first function")
        return v1

    def func2():
        v2 = "value2"
        func1()
        print ("This is the second function")

    fo = input ("Enter 1/2\n")
    if fo == '1':
        funcValue = func1()
    elif fo == '2':
        funcValue = func2()
    else:
        print ("invalid")

    print (funcValue)

Also you need to print first before returning something. After the return the function stops.

Or make a global variable, but don't do this if it is not necessary:

    v1 = ""
    v2 = ""
    def func1():
        global v1
        v1 = "value1"
        print ("This is the first function")
        return v1

    def func2():
        global v2
        v2 = "value2"
        func1()
        print ("This is the second function")

    fo = input ("Enter 1/2\n")
    if fo == '1':
        func1()
    elif fo == '2':
        func2()
    else:
        print ("invalid")

    print (v1)

