IDENTIFIERS IN PYTHON

Python Identifiers

An identifier is simply a name given to different entities, variables, class, functions, etc… At times, when we are going to create some variables, functions, or classes in our programs, we are going to have certain names for them. So now, we are going to have a look at what are identifiers, and what are the rules for naming an identifier.

The thing is that when we give some name to the variable for example, how we can know whether the name we are using, is valid or not? To determine that, there are some rules that we need to follow, and we are now going to have a look at those different rules related to the identifiers.

So, identifiers are nothing, but some name given to the different entities, like the variables, class, functions etc..

Now, let’s have a look at some of the different rules, which we need to follow, while we are creating an identifier.

  • Rule 1 – An identifier can be a combination of alphabets (lowercase or uppercase), numbers, or an underscore.
  • Rule 2 – An identifier cannot start with a number. So, 1variablename is not valid, but we can use the identifier variablename1. So, we can have number in our identifier, but not at the start.
  • Rule 3 – We cannot use keywords as identifiers. this
  • Rule 4 – The special symbols like! @, #, etc.. cannot be used in identifier.
  • Rule 5 – Python is case sensitive, so the identifiers count, and Count is not the same.
  • This point is not a rule actually, but it is something that you should practice. Whenever you are writing some identifier, like a name for variable, some function, or a class, you should be giving some meaningful name to it. For example, if you are creating some variable to store count of something, then you can name it anything(valid), but you should give some meaningful name to it, like count.

So, while creating an identifier, we would follow the above rules. Now the question is that, are we needed to remember these rules? Well, the answer is that we need not to. As we move on and practice many different programs, and make use of identifiers in our programs, we would get familiar with the concept, and most of the times, we would make correct identifiers in our programs.