So I am making a program to print the max element of a list,
arr=[1,2,41,6,9,8,5]
c=0
def findmax(x,y):
if(x>y):
global c=x
else:
global c=y
for x in range(0,len(arr)):
findmax(c,arr[x])
print(c)
When I try to run the program, it says error: invald syntax line 5 global c=x pointing to the = sign
How do I fix it?
global x = y, you can only writeglobal xand then laterx = y.max(arr)? you should declare a global in the beginning of the function and then you can use it later on. Plenty of examples over the web.globalus usually a huge antipattern. If you see it, you should definitely put some effort in rethinking your code.