How to distinguish between a variable and an identifier

0 votes
I am new to Python. Can someone explain to me the difference between an identifier and a variable?
Jul 31, 2019 in Python by Neel
• 3,020 points
13,746 views

3 answers to this question.

0 votes

Key Differences between Identifier and Variable

  1. Both an identifier and a variable are the names allotted by users to a particular entity in a program. The identifier is only used to identify an entity uniquely in a program at the time of execution whereas, a variable is a name given to a memory location, that is used to hold a value.
  2. Variable is only a kind of identifier, other kinds of identifiers are function names, class names, structure names, etc. So it can be said that all variables are identifiers whereas, vice versa is not true.

As identifier and variable names are user-defined names, it should be taken care that no two identifiers or no two variable names in a program should be the same. It will create a problem of ambiguity in a program.

answered Jul 31, 2019 by Arvind
• 3,000 points
why  vice versa is not true

Hi, @There,

Because, The identifier is only used to identify an entity uniquely in a program at the time of execution whereas, a variable is a name given to a memory location, that is used to hold a value.

0 votes

Variable is a name that is assigned to a memory location, which is used to contain the corresponding value in it. Variables are only the sort of identifiers. ... Similarly, as identifiers, two or more variables also can't have the same name in a program.

answered Dec 16, 2020 by Gitika
• 65,910 points
0 votes

An identifier actually identifies something, it's not the thing being identified. The splitting of hairs in this case is important.

They're typically kept track of by the symbol table.

If you have a location in memory that holds a value that changes, that's a variable. You need a way to reference that "thing." The identifier is the name you use in your program which represents where that value is and what datatype it is of.

Note, you could just as well have a value that changes that the compiler holds entirely in a register and never goes into memory; you still need a way to access it (like incrementing a loop index or a counter). The identifier is the thing you call it in the program, and it knows to look in a register and how to treat that value, rather than going to memory.

You could have a value that doesn't change in protected memory; the identifier again indicates where the value is, what kind of data it is, and clues the compiler into not letting you change the value.

In fact the constant value doesn't even have to be in memory. The identifier can just substitute the value in place of the identifier, given the appropriate compiler optimizations.

It's important to realize the identifier isn't a pointer type. Often it's addresses of where something is stored in the heap, a position on the stack, a temporary register, a location in memory where there's a function you intend to call, a location in the program flow for a break or a dreaded goto statement, etc.

You might think of it as the "name" of something, or a "symbol" you assign to it.

answered Dec 16, 2020 by Rajiv
• 8,880 points

Related Questions In Python

0 votes
1 answer

How to have values from a List1 into Columns Names and List 2 Values as Index for an Empty DataFrame

Try like this, it will give you ...READ MORE

answered Jul 10, 2019 in Python by Cherukuri
• 32,970 points
310 views
0 votes
1 answer

How to write a regular expression to check whether an input is an identifier or not?

As per the documentation, an identifer can ...READ MORE

answered Aug 8, 2019 in Python by Neel
• 3,020 points
1,866 views
0 votes
1 answer

How to read a text file into a string variable and strip newlines?

You could use: with open('data.txt', 'r') as file: ...READ MORE

answered Dec 23, 2020 in Python by Gitika
• 65,910 points
66 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,155 views
0 votes
0 answers
0 votes
1 answer

How to check whether something is a variable or a function in Python?

Suppose you have a variable defined in ...READ MORE

answered Jul 30, 2019 in Python by Arvind
• 3,000 points
272 views
0 votes
1 answer

Is it possible to read a text file into a string variable and then scrap the newlines?

This can be done easily in Python. ...READ MORE

answered Aug 7, 2019 in Python by Arvind
• 3,000 points
646 views