We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
the reason of * there is, it helps in passing the default value to the function so that the code can work.
The syntax of of getattr is :- getattr(Object,function)(vars)
As in this case our object is "L" and it doesn't contain the function passed in getattr, it will throw an error, so to avoid the error we are passing the default values of the function as mentioned in the question.
Like for the case (insert 0 5) it is like getattr(l,insert)(0,5).
We are passing 0 and 5 to insert so that it will add 5 at the index 0 in the list.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lists
You are viewing a single comment's thread. Return to all comments →
the reason of * there is, it helps in passing the default value to the function so that the code can work.
The syntax of of getattr is :- getattr(Object,function)(vars)
As in this case our object is "L" and it doesn't contain the function passed in getattr, it will throw an error, so to avoid the error we are passing the default values of the function as mentioned in the question.
Like for the case (insert 0 5) it is like getattr(l,insert)(0,5). We are passing 0 and 5 to insert so that it will add 5 at the index 0 in the list.