Keywords and Identifiers in Python



Keywords and Identifiers



Keywords

Keywords are the reserved words in Python. They convey a special meaning to the compiler. Keywords are reserved for special purpose so We cannot use a keyword as a variable name ,  function name or any other identifier.




Identifiers

Identifiers are the names used to identify things in your code. An identifier is a user-defined name to represent a variable, a function, a class, a module, or any other object. Any word that has not been commented out, delimited by quotation marks, or escaped in some other way is treated as an identifier by Python .

Rules for writing identifiers

1. A Python identifier can be a combination of uppercase/lowercase letters, digits, or an underscore. The following characters are valid:

Lowercase letters (a to z)

Uppercase letters (A to Z)

Digits (0 to 9)

Underscore (_)

For example,

Name1,first_name,LASTNAME,_NAME
Are valid identifiers.

But following are not valid identifiers:

"First-name"  as it contains “-“

"First name"   as it contains space


|First.name"     as it contains “.”

2. An identifier cannot begin with a digit. It can begin with a letter or _.
For example,

_ds, abc12 are valid

But 1a is invalid.

3. We cannot use a keyword as an identifier.

4. We cannot use special symbols in the identifier name. for example first@name, a$ are invalid identifiers.

Comments

Popular posts from this blog

working with python IDLE

Data Types in Python

introduction to python