xiº
xiº

Reputation: 4687

name of variables in Python

Is there a stylistic rule to call variables?

For example variables between different functions with same destination.

My question is about names in signatures of functions.

name = 'somevalue1'
path = 'some/value'
process(name, path)

What about names in signature? They should be same

def process(name, path):
     ...

Or maybe something like that:

def process(_name, _path)
    ...

Or

def process(name1, path1)
    ...

Upvotes: 4

Views: 126

Answers (3)

RemcoGerlich
RemcoGerlich

Reputation: 31250

For example variables between different functions with same destination.

It is important to realize that the variables in the calling function and the variables in the called function's signature have nothing to do with each other, and therefore it's perfectly fine to give them the same name if they mean the same thing.

If you have a name and a path, and a function that takes them as arguments, then it's a fine a choice to name them that:

def process(name, path):

(not that "process" itself is a good name, of course, but it's your example).

Then inside another function, you also have a name and a path. Of course, "name" and "path" are also great variables there! And you can use them to call process(). There's no reason whatsoever to use different names, they don't get in each other's way.

Upvotes: 1

Sergius
Sergius

Reputation: 986

Yes, there some global style rules like in that PEP8. Also, you can search for specific style guides of famous companies, like Google

Upvotes: 0

Exa
Exa

Reputation: 4110

Basically it is left to your own taste but there is indeed a style guide for Python called PEP8.

There are even some IDEs (like PyCharm) which support testing your code for PEP8 compliance on-the-fly.

Upvotes: 1

Related Questions