Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Dealing With Deprecated Keywords

To learn more about deprecated keywords, you can check out What’s New In Python 3.0.

00:00 In the last lesson you learned how to identify keywords, but what about those words that aren’t a keyword anymore? You will learn about them in this lesson.

00:11 There are two keywords that were deprecated in Python 3.0, print and exec. In the release notes of Python 3.0, you got the reasoning for it: “The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement.” And later, “Removed keyword: exec() is no longer a keyword; it remains as a function.”

00:41 So both former keywords have been basically replaced by a function with the same name. Does that mean that you are free to use them now? Well, let me show you why you still shouldn’t use them as a variable name in your code. So when you just type print, then you will see that it’s a built-in function and not a keyword.

01:05 And that means you can actually say, my variable name is print and I give it the string value of "CMYK". And if I call it, then CMYK is returned. However, if you want to use the print() function at any point later in your code, then you will get a TypeError, and this can really mess up your code. So don’t use print or exec as variable names.

01:39 It’s important to note that this word of caution isn’t just for the former print keyword, which is now a function. Basically you have to be careful every time when you reassign a built-in function with a variable name because you’re allowed to do this, but it’s not a good idea.

02:01 And I guess this is everything that I wanted to say about this topic. In the next lesson, I will recap this course and I will give you ideas about what to do next.

Become a Member to join the conversation.