Python del Statement17 Mar 2025 | 3 min read IntroductionIn Python, the del keyword is generally used to delete an object. Since everything in Python represents some kind of object, the del keyword can also be used to delete lists, variables, parts of a list, etc. The del statement does not return any type of value. Syntax of del statementNote: del is a keyword, and obj_name can be lists, dictionaries, user-defined objects, variables, etc.Examples of del StatementLet's look at some examples of del statements and try to delete some items. Example 1: In this program we will delete a variable using del statement Output: 35 Traceback (most recent call last): File " ![]() Example 2: In this program we will delete a list and slice list using del keyword Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ['a', 'b', 'c', 'd', 'e', 'f'] [0, 1, 3, 4, 5, 6, 7, 8, 9] [0, 1, 3, 4] ['a', 'c', 'd', 'e', 'f'] Traceback (most recent call last): File " ![]() Example 3: In this program, we will use the del statement to delete dictionaries and key-value pairs Output: {'up': 'down', 'forward': 'backward', 'small': 'down'} {'short': 'long', 'you': 'me', 'Jack': 'John'} {'forward': 'backward', 'small': 'down'} Traceback (most recent call last): File " ![]() Example 4: Delete a User-Defined Object Output: Name: John wik Age: 26 Address: C-26, London Phone No: 61562347 Traceback (most recent call last): File " ![]() Next TopicLooping technique in Python |
Introduction: Flowers have always been a source of fascination and inspiration for humans. The beauty and diversity of the natural world are something that has been celebrated in art, literature, and science for centuries. With the advancements in machine learning and computer vision, we now can...
8 min read
A computer science engineer, a part of encrypting the world, must know the basics of hacking. Hacking is the process of getting access to a system of which we are not supposed to have. Such as login in to the email account without authorization is a...
7 min read
Difference between Modules and Packages in Python It is often that many coders and amateur programmers may confuse between a module and a package. The problem generally arises when it becomes hard to identify when and where a module or a package should be implemented. In the following...
2 min read
Learn : A Step-by-Step Approach Basic idea on Python language is essential for programmers and Network engineers. Who is Network Engineer, and What Do They Do? A Network Engineer plans, carry out and supervises a Network. Furthermore, since networks are intricate and, complex, transforming nature, they likewise perform checks...
6 min read
The problem statement of this tutorial is that if we are given a sorted array of length n and an integer x, then we need to find the lower insertion index of x in the given array. The lower insertion index of any element is the...
5 min read
? Sets and Lists are the data structures in Python that consist of groups of data elements. However, these two data structures have some significant differences too. In specific, the lists perform a few ranges of mathematical operations that are useful to search for particular elements -...
4 min read
In computer vision and image processing, colors hold a wealth of information. They define the aesthetics of an image, highlight intricate details, and convey emotions that words often struggle to express. Behind the captivating visual world lies a complex framework of color spaces, each offering a...
3 min read
You might need to locate the first item in a Python iterable, like a list or dictionary, that meets a specific requirement at an indeterminate point in your Python trip. The sole exception is when it is necessary to confirm "that a" specific item is present in...
13 min read
In this tutorial, we are going to learn about coroutine in Python. We will discuss the coroutines, subroutine, execution of coroutines, and closing of coroutine in Python in details. Before we start learning about coroutine, we must have a basic understanding of subroutines in Python. So,...
7 min read
In this tutorial, we will solve a problem on Binary Tree data structure. The problem statement is that if we are provided with the root node of the binary tree, the target node, and the distance value k, we need to return the list of all...
8 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India