91

All members are camel case, right? Why True/False but not true/false, which is more relaxed?

Joan Venge
  • 315,713
  • 212
  • 479
  • 689
  • All members are camel case, right? No, it depends. Use **snake_case** to declare variables, functions, modules and packages (ex: first_name, calculate_sum). For Constants, use all uppercase and separate words by underscore if needed (ex: HEADING_COLOR). For classes, use **PascalCase** (ex: StudentRecords) – Akshay Katiha Jul 09 '23 at 09:02

4 Answers4

88

From Pep 285:

Should the constants be called 'True' and 'False' (similar to None) or 'true' and 'false' (as in C++, Java and C99)?

=> True and False.

Most reviewers agree that consistency within Python is more important than consistency with other languages.

This, as Andrew points out, is probably because all (most)? built-in constants are capitalized.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
James Sulak
  • 31,389
  • 11
  • 53
  • 57
  • Thanks James, but isn't the default casing is camel casing in python? – Joan Venge Feb 06 '09 at 18:21
  • 3
    It is for classes. There are different rules for other things. Scroll to "Naming Conventions": http://www.python.org/dev/peps/pep-0008/ – Baltimark Feb 06 '09 at 19:49
  • 11
    In that case, how come other constants aren't lower case also? – Razor Storm Sep 07 '11 at 04:19
  • 20
    the real question is: Why is 'None' capitalized in the first place? I get errors again and again because I write a constant in lowercase... – xeruf May 17 '17 at 16:44
19

All of python's built-in constants are capitalized or [upper] CamelCase:

Andrew Jaffe
  • 26,554
  • 4
  • 50
  • 59
6

Here's a possible explaination:

I see that naming conventions are such that classes usually get named CamelCase. So why are the built-in types named all lowercase (like list, dict, set, bool, etc.)?

Because most of them originally were types and factory functions, not
classes - and a naming convention is not a strong reason to make backwards incompatible changes. A different example: the new builtin type set is based on (altough not exactly equal to) the Set class from the sets module

Stephen
  • 4,176
  • 2
  • 24
  • 29
-4

In python only the 3 keywords True ,False and None are started with capital letters. I think This is to differentiate these 3 keywords from others. These 3 keywords can be used as literals or values where as other keywords not. For example

a=True is correct but a=for is wrong