python keywords - reserved words

problem

You’re learning Python and came across the keywords or identifiers. Each programming language has its own reserved words that are used to write up the program. Those words cannot be used by the programmer, for example as variable names or as function names. In this post we will see a list of Python’s reserved words.

SOLUTION

The identifiers are words, therefore can be saved in a string variable. String offers a function for checking whether the contents of a string matches an identifier or not; regardless if it’s written with capital or lower letters. For example we can check as follows:

keywords.py
				
					word = "break"
word.isidentifier() #will give us True
				
			
keywords.py
				
					word = "car"
word.isidentifier() #will give us False

				
			
keywords.py
				
					Word = "tRue"
word.isidentifier() #will give us True
				
			
keywords

The keywords are listed below:

  • False
  • True
  • None
  • await
  • if
  • else
  • elif
  • import
  • from
  • as
  • pass
  • try
  • except
  • finally
  • raise
  • in
  • is
  • class
  •  global
  • nonlocal
  • while
  • for
  • break
  • continue
  • assert
  • del
  • not
  • and
  • or
  • with
  • async
  • yield
  • def
  • return
  • lambda

conclusion

In this post we saw the keywords of Python that are disallowed for usage by the programmer.

Share it!

Facebook
Twitter
LinkedIn
Reddit
Picture of Ellion

Ellion

Professional IT consultant, writer, programmer enthusiast interested in all sorts of coding.
Eats all cookies 🍪

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x