del in Python
del is used to delete a reference to an object. Any variable or list value can be deleted using del.
del Keyword in Python
In this code, the variables my_variable1
and my_variable2
are initially defined and then deleted using the del
keyword. When you try to print them after deletion, you will encounter a NameError
because the variables no longer exist.
Python3
my_variable1 = 20 my_variable2 = "w3wiki" print (my_variable1) print (my_variable2) del my_variable1 del my_variable2 print (my_variable1) print (my_variable2) |
Output
20
w3wiki
NameError: name 'my_variable1' is not defined
Python Keywords
Every language contains words and a set of rules that would make a sentence meaningful. Similarly, in Python programming language, there are a set of predefined words, called Keywords which along with Identifiers will form meaningful sentences when used together. Python keywords cannot be used as the names of variables, functions, and classes.
In this article, we will learn about Python keywords and how to use them to perform some tasks.