Identifiers and Reserved Words

Python Identifiers:

Identifier the name itself says a lot about itself, Identify or Identification and Identification can be done by naming.

So identifier is basically the name of the variable, class, function etc.

For ex:

  1. x= 10 (Here x is a identifier which is a variable stores the value of type int.)
  2. def function1() : (Here function1 is a identifier which is a function).

A name cannot be given directly, we need to follow some rules to write a identifier which are…

  1. Identifier can be a combination of letters in lowercase (a-z) or uppercase (A-Z) or digits (0-9) or an underscore.
  2. Identifier cannot start with number or digit.
  3. Keywords cannot be and should not be used as identifier.
  4. No special symbol except underscore(_) is allowed.
  5. Identifier can be of any length.

Some of the valid identifiers are

myClass, number1, number_2, var1 etc.

Python Reserved Words:

Reserved words are keywords which cannot be used as an identifiers. The compiler is well aware of these words and will always take them as reserved words if tried in place of identifiers.

Basically reserved words makes an programming language, master these reserved words half of your job is done.

There are in all 33 Reserved words in Python Language.

  1. True (Capital T).
  2. False (Capital F).
  3. None (Capital N).
  4. and
  5. or
  6. not
  7. is
  8. if
  9. else
  10. elif
  11. while
  12. for
  13. break
  14. continue
  15. return
  16. in
  17. yield
  18. try
  19. except
  20. finally
  21. as
  22. class
  23. def
  24. pass
  25. import
  26. from
  27. raise
  28. assert
  29. global
  30. nonlocal
  31. lambda
  32. del
  33. with

We will see in details all these keywords in upcoming tutorials.

If we want to list down all the keywords just type

>> import keyword
>> keyword.kwlist

This will list down all the keywords.

I made this very small not to make it lengthy and boring. Its better to take small steps understand throughly and go on.

So, its time for Note: In the previous tutorial we studied Python is platform Independent and also read that it can be blend with C/CPP/Java etc code…. but here is the drawback if Python is blend with any of the Platform dependent language Python will lose it platform independent feature. 

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