Search code examples
pythonreadabilitycoding-style

variables naming convention for abbreviation in Python


I read PEP8, and abbreviations for python, and I have question regarding the variable name itself.
I'm familiar with the famous variable abbreviations, For example, :

  1. str for string
  2. cnt for counter
  3. cfg for configuration

It's came into my mind after thought about an appropriate name for a variable that contain first instruction, I thought about fisr_inst or first_instr or even first_instruction but couldn't find any document regarding this in Python.
but is there a table, or a list of all those abbreviation conventions in python? did I miss it?

EDIT - I didn't asked for appropriate name for "my variable name", I asked if there a table or list that contain some abbreviation for common use in python


Solution

  • Explicit and verbose is the recommended standard as far as naming things is concerned. EXTREMELY common abbreviations that are impossible to be mistaken are used to shorten line length, but don't think too far into those.

    i for index, j for secondary index (in a 2D array), f for file, del for delete, str for string, cnt for count, cfg for config, prod for production, dist for distribution, fact for factorial, etc.

    I don't know what use you have for first_instruction, but I wouldn't try to shorten either word - that is a solid variable name.

    edit: My opinion has changed on the matter so I figured I'd share. I've now worked on distributed teams where contributing members have learned English later or are still learning English. Nowadays, I simply never abbreviate because I was only doing it to cut a few characters anyways 🤷‍♂️