How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use the Python string delete del() function with basic syntax and many examples for better understanding.
Python string delete – del() is used to perform deletion operation, the del () function is used in the string. Using this function, we can delete the entire string variable only.
This article will answer the following questions:
- How to delete variable in Python?
- How to delete a string object in Python?
Syntax:
del (<String_variable_name>)
Input Parameters:
- string_variable_name : where string is a string variable which we need to delete it.
Example:
#delete whole string
mystr='I like python'
del (mystr)
print(mystr)
Output of example 1
Traceback (most recent call last):
File “C:/Users/Desktop/exam.py”, line 4, in
print(mystr)
NameError: name ‘mystr’ is not defined
In the above example, we apply to delete operation on the string variable as mystr. We are deleting the whole string by del (mystr) so, the output displays an error as the name ‘mystr’ is not defined because ‘mystr’ is already deleted in the previous step.
Note: In string, element deletion is not possible. but there is another workaround to tweak 🙂 think of it and let us know what you get in the comments?
In this tutorial, you have learned how to use python string delete del() function to delete the whole string variable.
If you have an inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback.But remember to understand the concept very well, you need to practice more.
Hopefully, it was clear and concise.
Similar Python Functions to String Delete:
- min(string) : It returns a minimum value of string.
- max(string) : It returns a maximum value of string.
- len(string) : It returns type of string , if passed variable is string.
- str(seq) : It converts a sequence into string.
- type(string) : It returns type of string, if passed variable is a string.
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials list : access all python tutorials.