Rules/conventions for naming variables

Rules for variable names

  1. Must start with a letter or underscore (_)
  2. Cannot contain punctuation characters (ex) @$%^*
  3. Are case-sensitive (ex) name and Name are two different variables
  4. Cannot be a reserved word:
    1. and
    2. assert
    3. break
    4. class
    5. continue
    6. def
    7. del
    8. elif
    9. else
    10. except
    11. exec
    12. finally
    13. for
    14. from
    15. global
    16. if
    17. import
    18. in
    19. is
    20. lambda
    21. not
    22. or
    23. pass
    24. print
    25. raise
    26. return
    27. try
    28. while
    29. with
    30. yield

*These are rules, not conventions. That is, rules must be followed and go beyond simple readability guidelines.

Conventions for variable names

  1. Class names start with an upper case letter
  2. Private variables start with an underscore
  3. Strongly private variables start with two underscores
  4. Language-defined special name variables also end with two underscores
Advertisements