To learn more about the concepts covered in this lesson, you can check out History of the Python language (syntax).
00:00 In the last lesson, you got an overview of all the keywords. In this lesson, you will learn what keywords in Python actually are, and you will learn that there are normal keywords and soft keywords, and what the difference between them is.
00:28 That means you’ll never have to import them into your code. They are fundamental building blocks. They are essential for Python syntax, but they also make the Python programming language more human-readable.
00:54 Now you might wonder why the last two bullets don’t have the checkmark on our friendly green background. Well, I did this on purpose to foreshadow that these are key differences to soft keywords.
Same case if I just type
and. This one also raises a
SyntaxError. You will learn more about how you actually use them correctly as building blocks in your Python code in the next lesson. For now, just remember this
SyntaxError that’s raised.
Python keywords are special, reserved words. That means you can’t just use them as variable names. If you type
pass = "hello", you will also get a
pass is a keyword and you can’t use it like that.
Let’s move to soft keywords and see how they behave differently. If I just type
match, I will also get an error. So that’s not that different to some of the keywords I just typed above, but this error is different. So it’s not a
SyntaxError, which would mean I used this keyword wrong. But it’s a
NameError, which means the variable
match isn’t known to Python yet.
You won’t get a
SyntaxError, and you are allowed to do this. However, besides using them as normal variable names, you are allowed to use them in a special way. Now with Python 3.10, you can use
_ (underscore) for the structural pattern matching.
04:05 So what you’re seeing here, that’s what is meant with the word soft. You can use them as normal variables, but they are also fundamental building blocks in your Python code. For example, structural pattern matching. Before we move on, let me quickly prove that this function works. Let’s call it.
04:32 The reason why you’re now having soft keywords as well is because keywords in general can change over time. So before Python 3, there were already a bunch of keywords. And with Python 3.0, there were a few changes introduced.
However, not as keywords but as soft keywords. That means if you have an existing codebase, and you use variable names like
case, you don’t have to change your codebase just to work with Python 3.10.
Become a Member to join the conversation.