Naming the variable 

Naming variables may seem to be a minor topic, but trust us, adopting a good habit of proper naming will save you a lot of time and nerves down the road. Do your best to name variables wisely and consistently. Ambiguous names will make code extremely hard to read, understand, and debug, for no good reason.

Now, technically there are just three requirements for variable names:

  • You cannot use reserved words: False, class, finally, is, return, None, continue, for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except, in, or raise. You also cannot use operators or special symbols (+, -, /, *, %, =, <, >, @, &) or brackets and parentheses as part of variable names.
  • Variable names can't start with digits.
  • Variable names can't contain whitespace. Use the underscore symbol instead.

On top of that, there are also some general naming conventions. You don't have to, but it is strongly recommended to follow them:

  • Name your variables meaningfully and consistently, so that readers will understand what they are meant to be. Some examples are counter, car, and today.
  • Apply snake_case for naming: Use lowercase letters that are joined by an underscore. Some examples are my_car, app_counter, and get_settings.

For broader recommendations on naming and coding style in general, please read PEP8 -- Style Guide for Python Code (https://www.python.org/dev/peps/pep-0008/#function-and-variable-names).

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset