- #1
- 2,168
- 193
Sometimes, when I code something, I am naming the local variables in the function same as the global variable. Such as,
As you can see my_var is defined globally but also used locally inside the function. My question is, in these kind of situation, is there a convention for naming the local variables if we want to stick with a base name my_var ?
For instance is this a good naming option
or it can be something else.
Code:
my_var = 13
def iseven(my_var):
if my_var % 2 == 0:
return True
return False
print(iseven(my_var))
As you can see my_var is defined globally but also used locally inside the function. My question is, in these kind of situation, is there a convention for naming the local variables if we want to stick with a base name my_var ?
For instance is this a good naming option
Code:
my_var = 13
def iseven(_my_var):
if _my_var % 2 == 0:
return True
return False
print(iseven(my_var))
or it can be something else.