In python, can you manipulate a variable such as an int inside a function directly without including it as a return value? For example: a = 0 b = 0 def function(x): if x = 0: a += 1 return True else: b += 1 return False print function(0) I had this problem when i tried to track for which part of the code is executed in the example used in this "10. Dictionaries. How to Think Like a Computer Scientist" about Hints using the Fibonacci sequence. Thank you in advance.
Are you familiar with the concept of a global and scope? Two references on the topic: http://www.python-course.eu/python3_global_vs_local_variables.php http://www.diveintopython.net/html_processing/locals_and_globals.html
a = 0 b = 0 def function(x): global a, b if x == 0: a += 1 return True else: b += 1 return False print function(0) print a, b
You can use "global" to access global variables. And remember, use "=" to attribution and "==" to compare
Join our real-time social learning platform and learn together with your friends!