Python: Identifier & Keyword


Identifier

In Python name of any variable, function, class, module, and object is called an identifier. An identifier can start with a lowercase or uppercase character or an underscore (_) followed by any number of underscores, letters, and digits. All identifiers in python are case sensitive.

Example Variable: distance=10

In the above example distance is an identifier.

Example Function:  def calculateTotal(prices)

In this above example calculateTotal is identifier.

Example class:  class User

In this above example User is identifier.

Keyword or Reserve Word

Keywords are also called as reserved words in python. So keywords cannot be used as an identifier to name variables or object or functions. Few of the keywords are listed below.

Example: if, else, elif, for, while, break, continue, pass etc.

Following is the list of reserved keywords in Python 3. You can explore each keyword examples and detail on click of each.

andexceptlambdawith
asfinallynonlocalwhile
assertfalseNoneYield
breakfornot
classfromor
continueglobalpass
defifraise
delimportreturn
elifinTrue
elseistry

Python 3 has 33 keywords while Python 2 has 30. The print has been removed from Python 2 as keyword and included as built-in function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s