Top Built-in Functions for Python Data Structures.
My article is for everyone! Non-members can click on this link and jump straight into the full text!!
Today, we are going to learn about some of the most useful built-in functions in Python for common secondary data types or data structures. When I was in college I wrote everything from scratch (as is common for people who migrated to Python from lower-level computer languages like C/C++ and Java) which led me to waste a considerable amount of time re-writing functions and features that had already been included in the language itself.
Then I came across built-in functions in Python and I started using them; this led to my code being more efficient, more readable.
Python has a set of built-in methods that you can use on lists.
append()
- It is used to insert an element to the end of a list.
fruit_list =['apple','banana','orange']
fruit_list.append('grapes')
print(fruit_list)> ['apple', 'banana', 'orange', 'grapes']
clear()
- It is used to remove all the elements from the list.
fruit_list =['apple','banana','orange']
fruit_list.clear()
print(fruit_list)