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.
did you see my explanation below? give it an upvote if helpful. @RahulDamineni took a crack at it too. What about it do you not understand?
--
In this example given by @SemperPeritus, he's providing a function log_in that takes name, password, captcha as arguments.
In general, you pass in arguments like so:
function(arg1,arg2,arg3)
But, if you put them in a list such as:
function([arg1,arg2,arg3])
then it's like you're only passing in 1 argument (the list) and you'll get an error saying function was expecting 3 arguments and only got 1.
On the other hand if you were to include * it would "unpack" the list (imagine the list is a suitcase and the elements are pieces of clothing you want to put on the bed to look at individually. you can't do that without unpacking the suitcase, right?) so that it would still work:
function(*[arg1,arg2,arg3])
becomes
function(arg1,arg2,arg3)
So *user changes from a list:
user=[name,password,captcha]
to arguments:
*user=name,password,captcha
So now log_in will work without errors because it was passed 3 arguments instead of 1!
Want to learn more about a related topic in Python called zip? Check out my blog post: medium.com/@PrintSupWorld/unzipping-python-2-340701d300a6
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Print Function
You are viewing a single comment's thread. Return to all comments →
did you see my explanation below? give it an upvote if helpful. @RahulDamineni took a crack at it too. What about it do you not understand?
--
In this example given by @SemperPeritus, he's providing a function
log_in
that takesname, password, captcha
as arguments.In general, you pass in arguments like so:
But, if you put them in a list such as:
then it's like you're only passing in 1 argument (the list) and you'll get an error saying
function
was expecting 3 arguments and only got 1.On the other hand if you were to include
*
it would "unpack" the list (imagine the list is a suitcase and the elements are pieces of clothing you want to put on the bed to look at individually. you can't do that without unpacking the suitcase, right?) so that it would still work:becomes
So
*user
changes from a list:to arguments:
So now
log_in
will work without errors because it was passed 3 arguments instead of 1!Want to learn more about a related topic in Python called
zip
? Check out my blog post: medium.com/@PrintSupWorld/unzipping-python-2-340701d300a6