1

I am new to python programming, please assist me.

I don't want to overwrite the Admin but it is forcing me to do that.

def funk(Admin="subhanshu",*users,**additional):
    print("Admin is", Admin)
    print("users are", users)
    print("additional are", additional)

When I run the function, it is throwing an error.

funk(pass,'arun',"abcd",name='prakhar',age=23)

invalid syntex

Please help me how to call a function without over-riding the value of Admin in the function.

1
  • what is pass you need to define it and accommodate it in funk function Commented Mar 22, 2019 at 6:02

1 Answer 1

1

Change the order of parameters in your function signature.

>>> def funk(*users, Admin='subhanshu', **additional):
...     print("Admin is", Admin)
...     print("users are", users)
...     print("additional are", additional)
...
>>> funk('these', 'are', 'all', 'users', this='is', additional=True)
Admin is subhanshu
users are ('these', 'are', 'all', 'users')
additional are {'this': 'is', 'additional': True}

The way that you have defined the function means that the first positional argument passed to the function will always be assigned to the Admin variable. By defining the function so that Admin comes after the positional arguments (*users) with a default value, it becomes an optional keyword argument.

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.