1
def func(*arg):
    for i in arg:
        print(i)

Here if a user is allowed to enter the arguments using input function (python 3.x).

Eg : "Hello,World,Good,Morning"

If we want each word which is seperated by comma must be passed as argument...

Eg: func("Hello",World","Good","Morning")

How can I solve this problem?

1
  • 2
    Is there a reason you need this function to take a variable number of arguments, instead of just taking a list of arguments? Commented Sep 9, 2013 at 19:42

1 Answer 1

5

Use * during function call too. str.split splits the string into a list and then unpack the list items into individual arguments using *.

>>> strs =  "Hello,World,Good,Morning"
>>> spl = strs.split(',')
>>> spl
['Hello', 'World', 'Good', 'Morning']
>>> func(*spl)
Hello
World
Good
Morning
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.