00:15 The first way of identifying keywords in your code is using a code editor that supports syntax highlighting. With syntax highlighting, words in your code are colored or even formatted differently if they are somehow special. And what could be more special than Python keywords?
So here you see three examples you already saw in the former lesson, and the keywords—now you might remember some of them—are all in pink. So by just looking at this screen, you can easily spot that
lambda down there are Python keywords.
Another way of identifying keywords is just trying to use them and see if you get any syntax errors. So if you try to assign the string
"1234" to a variable named
pass, Python will throw a
You already saw this in one of the former lessons why this is. Same if I just type
while. You will also get a
SyntaxError. If this wouldn’t be keywords, you would get a
NameError that the variables are undefined, or it would just work.
But this is kind of like a harsh way of finding out what a Python keyboard is, or if a certain word is a Python keyword. Okay, I know I said that I will show two ways, but if you remember at the beginning of this course, I also showed you that you could import the
keyword module to list all keywords, so basically this is a way of finding out what the Python keywords are as well.
Same goes if you type something that isn’t a Python keyword or anything that Python knows of. Then Python will let you know that there is no Python documentation found for this word—in this example,
Become a Member to join the conversation.