I have a question about the scope in python functions. I've included an example that demonstrates the issue I am having.
fun0 redefines the first entry in varible c's list. This change is reflected outside of fun0, even when I don't return any values from fun0.
fun1 redefines the variable c entirely, but the change isn't reflected outside of fun1. Similarly, fun2 redefines c, and the change isn't reflected outside of fun2.
My question is, why does fun0 modify val3 in the main function, while fun1 and fun2 don't modify val4 and val7, respectively?
def fun0(a, b, c):
c[0] = a[0] + b[0]
return
def fun1(a, b, c):
c = a[0] + b[0]
return
def fun2(a, b, c):
c = a + b
return
def main():
val1 = ['one']
val2 = ['two']
val3 = ['']
fun0(val1, val2, val3)
print val3
val4 = []
fun1(val1, val2, val4)
print val4
val5 = 1
val6 = 1
val7 = 0
fun2(val5, val6, val7)
print val7
return
if __name__=='__main__':
main()