clear() of Lists in Python
clear() of List in Python
The clear() method removes all the elements present in a list. Basically it is used to clear the list. clear() method does not take any parameters. It clears the whole list and it does not return anything.
clear() of Lists
The clear() method of lists in Python is used to remove all elements from a list, effectively making the list empty. This method is useful when you want to reset a list or free up memory occupied by its elements, making it ready for new data.
Syntax :
Return Type :
The clear() method does not return any value.
#clear() in python list myList = [ 1, 2, 9, 10, 4, 4, 2 ] print(myList) #all the values deleted from list myList.clear() print(myList)
Output : [1, 2, 9, 10, 4, 4, 2] []
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment