0

Can I use the same var name when passing a value to a function in Python, like this?:

def function(i):
    z=i+1
    print (z)

for i in range (0,100):
    function(i)

Or should I do it like this:

def function(x):
    z=x+1
    print (z)

for i in range (0,100):
    function(i)

what is the best practice?

1 Answers1

0

There's no technical reason why you should't use it, yet I'd strongly suggest to get rid of habit of naming variables like i or f or so, instead of number_of_beds_in_reserved_room (or camelCase if you prefer so :). By keeping bad habits with short variable names you save nothing nowadays, yet risk a lot of stepping of variable name shadowing which may be pretty damn hard to debug. RAM is cheap. Your time is not.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141