Computer Science, asked by vedantnairvn16, 11 months ago

What are the rules to be followed to name the identifiers? in pyhon

Answers

Answered by rejibala
3

Explanation:

Python Identifiers

Python Identifier is the name we give to identify a variable, function, class, module or other object. That means whenever we want to give an entity a name, that’s called identifier.

Sometimes variable and identifier are often misunderstood as same but they are not. Well for clarity, let’s see what is a variable?

Variable in Python

A variable, as the name indicates is something whose value is changeable over time. In fact a variable is a memory location where a value can be stored. Later we can retrieve the value to use. But for doing it we need to give a nickname to that memory location so that we can refer to it. That’s identifier, the nickname.

Rules for writing Identifiers

There are some rules for writing Identifiers. But first you must know Python is case sensitive. That means Name and name are two different identifiers in Python. Here are some rules for writing Identifiers in python.

Identifiers can be combination of uppercase and lowercase letters, digits or an underscore(_). So myVariable, variable_1, variable_for_print all are valid python identifiers.

An Identifier can not start with digit. So while variable1 is valid, 1variable is not valid.

We can’t use special symbols like !,#,@,%,$ etc in our Identifier.

Identifier can be of any length.

Though these are hard rules for writing identifiers, also there are some naming conventions which are not mandatory but rather good practices to follow.

Class names start with an uppercase letter. All other identifiers start with a lowercase letter.

Starting an identifier with a single leading underscore indicates the identifier is private.

If the identifier starts and ends with two underscores, than means the identifier is language-defined special name.

While c = 10 is valid, writing count = 10 would make more sense and it would be easier to figure out what it does even when you look at your code after a long time.

Multiple words can be separated using an underscore, for example this_is_a_variable.

Please mark me the branliest

Similar questions