"Gandalf" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On May 30, 12:14 am, John Henderson <[EMAIL PROTECTED]> wrote: >> Gandalf wrote: >> > how do i write this code in order for python to understand it >> > and print me the x variable >> >> > x=1 >> > def aaaa(): >> > x++ >> > if x > 1: >> > print "wrong" >> > else : >> > print x >> >> > aaaa() >> >> Example: >> >> x=1 >> def aaaa(x): >> x += 1 >> if x > 1: >> return "wrong" >> else : >> return x >> >> print aaaa(x) >> >> John > > mmm isn't their any global variable for functions?
how about def aaaa(): y = x+1 if y > 1: return "wrong" else: return y but if you really have to modify x outside of the scope of the function, well, i guess one possibility is to return a tuple, one element being a string that may or may not contain the word "wrong" and another being x, and then whatever's calling aaaa can change x in their own scope based on the return value. but other than that, the normal way to affect a variable beyond the scope of your function is to make a class and affect a class variable. although there is always the 'global' statement also. -- http://mail.python.org/mailman/listinfo/python-list