Search code examples
pythonnaming-conventionspep8

What's convention for naming a class or method as "class" in Python?


Let's say I have a class in Python like this:

class Student:
    def __init__(self, classs):
        self.classs = classs

Now, what's convention for naming a parameter (and class property) classs? I saw classs as well as klass and I'm wondering: is there some convention for it? Didn't find it in PEP8.


Solution

  • PEP 8 advises to use a trailing underscore in that case: class_.

    See https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles for details:

    single_trailing_underscore_ : used by convention to avoid conflicts with Python keyword, e.g.

    Tkinter.Toplevel(master, class_='ClassName')