0

I read Naming Conventions in PEP 8 – Style Guide for Python Code.

And, it says:

Function and Variable Names
......
mixedCase is allowed only in contexts where that’s already the prevailing style (e.g. threading.py), to retain backwards compatibility.

Next, I read threading — Thread-based parallelism.

And, it says:

Note: In the Python 2.x series, this module contained camelCase names for some methods and functions. These are deprecated as of Python 3.10, but they are still supported for compatibility with Python 2.5 and lower.

So, is camelCase basically deprecated or not allowed to use in Python?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
  • you can use it if you want to be a solo ranger or just try something different, I don't think anyone would mind too much honestly. – rv.kvetch Jun 09 '22 at 17:00
  • 1
    The `logging` module is a good example, i always find it a bit odd that the methods are implemented in camelCase, but I guess it doesn't detract from it too much, as long as it functions as expected anyway. – rv.kvetch Jun 09 '22 at 17:02
  • 2
    Style guides are just suggestions — not rules, no? – 0x263A Jun 09 '22 at 17:02
  • Depends on context. I think the way the docs put it is great - follow whatever the prevailing style is. `snake_case` seems much easier to read to me, but several modules utilize `camelCase` so it is reasonable to use it when working with those. – will-hedges Jun 09 '22 at 17:05
  • 1
    [Related question](https://stackoverflow.com/questions/71445169/where-to-use-camelcase-in-python-according-to-pep-8) – 0x263A Jun 09 '22 at 17:16
  • 1
    If you are looking for a job, stick to PEP8 style... writing Python code styled according to conventions of other languages, or your own arbitrary style, looks less professional. Of course it still works fine, and as others have pointed out there are (old) parts of the Python stdlib that don't follow that naming convention – Anentropic Jun 09 '22 at 17:25
  • Its use is not deprecated nor disallowed, but you should follow the [PEP 8 Naming Conventions](https://www.python.org/dev/peps/pep-0008/#naming-conventions) whenever feasible. I've always hated it because it's not that readable and makes code look "schizoid" IMO. – martineau Jun 09 '22 at 17:27

2 Answers2

2

First of all, let's clarify:

CapitalizedWords (or CapWords, or CamelCase).

mixedCase (differs from CapitalizedWords by initial lowercase character, as in your case you wrote 'camelCase')

Now, some confusion arises with older Python 2, but the most recent Python 3 versions, follows a more pythonic way using the PEP convention, and:

Class names should normally use the CapWords convention.

And, Function names should be lowercase, with words separated by underscores as necessary to improve readability (aka snake_case).

Variable names follow the same convention as function names.

Constants follow UPPERCASE

nferreira78
  • 1,013
  • 4
  • 17
0

In Python you're free to name variables however you'd like. This means that declarations in camelCase will be accepted by the interpreter just fine.

However the Python community has agreed that snake_case should be used for functions and variable names, and CapCase should be used for class names. In general it's better to follow these guidelines to make your Python code more easily readable, even though it is not required by the Python interpreter.

There are some cases where camelCase became the prevailing convention for naming variables, often when a library was ported over from another language where camelCase is preferred. One such example is pyQt, which is ported from C++ (here's an example from their docs). In these cases it's more important to be consistent than conformant, so it's preferred if you stick with the same style for the whole codebase.