I'm getting errors while declaring a simple 'sum of two numbers' function if I'm using it before its declaration in Python 3.8.0
I tried both ways, declaring the function before and after its usage. In the case when I declared the function before its usage (to be specific, at the top of my code), my program is simply running fine. But when I tried to declare the sum function after its usage (in this case, at the extreme bottom of the code), it gave me an error : " 'int' object is not iterable ".
m = sum(var1,var2) # usage of the function
print(m)
# here, the function is declared at the bottom, i.e., after the usage.
# the error is in line 7 of the code
def sum(a,b): # The function
return int(a+b)
#IN CASE OF THE FUNCTION DEFINITION AFTER ITS USAGE, THE FOLLOWING ERROR IS COMING:
Traceback (most recent call last):
File "C:/Users/yvish/AppData/Local/Programs/Python/Python38/sum.py", line 7, in <module>
m = sum(var1,var2)
TypeError: 'int' object is not iterable
sum()is a built-in function. Don't overwrite it!