test function:
You can use multiple arguments represented by *args and multiple keywords represented by **kwargs and passing to a function:
def test(*args, **kwargs):
print('arguments are:')
for i in args:
print(i)
print('\nkeywords are:')
for j in kwargs:
print(j)
Example:
Then use any type of data as arguments and as many parameters as keywords for the function. The function will automatically detect them and separate them to arguments and keywords:
a1 = "Bob" #string
a2 = [1,2,3] #list
a3 = {'a': 222, #dictionary
'b': 333,
'c': 444}
test(a1, a2, a3, param1=True, param2=12, param3=None)
Output:
arguments are:
Bob
[1, 2, 3]
{'a': 222, 'c': 444, 'b': 333}
keywords are:
param3
param2
param1
Answer from imz22 on Stack Overflowtest function:
You can use multiple arguments represented by *args and multiple keywords represented by **kwargs and passing to a function:
def test(*args, **kwargs):
print('arguments are:')
for i in args:
print(i)
print('\nkeywords are:')
for j in kwargs:
print(j)
Example:
Then use any type of data as arguments and as many parameters as keywords for the function. The function will automatically detect them and separate them to arguments and keywords:
a1 = "Bob" #string
a2 = [1,2,3] #list
a3 = {'a': 222, #dictionary
'b': 333,
'c': 444}
test(a1, a2, a3, param1=True, param2=12, param3=None)
Output:
arguments are:
Bob
[1, 2, 3]
{'a': 222, 'c': 444, 'b': 333}
keywords are:
param3
param2
param1
You can change it to:
def WorkDetails(link, details):
Then invoke it as:
details = [ AllcurrValFound_bse, AllyearlyHLFound_bse,
AlldaysHLFound_bse, AllvolumeFound_bse,
AllprevCloseFound_bse, AllchangePercentFound_bse,
AllmarketCapFound_bse ]
workDetails(link, details)
And you would get the different values out of details by:
AllcurrValFound_bse = details[0]
AllyearlyHLFound_bse = details[1]
...
It would be more robust to turn details into a dictionary, with the variable names as keys, so take your pick between a few more lines of code vs. defensive programming =p
pass multiple parameters to a function from a single input
How to pass multiple tuples into a class.__init__()
Passing function with multiple arguments to scipy.optimize.fsolve
You can't put the function() call in before the fsolve() call because it would evaluate first and return the result. You have to pass it the function handle itself, which is just fsolve. Also x has to be the first argument of the function.
import scipy.optimize as opt args = (a,b,c) x_roots, info, _ = opt.fsolve( function, x0, args )More on reddit.com
Function parameter as a tuple
Videos
I have this
create_user(input("enter a name followed by a password\n"))and this function
def create_user(userName, passwd):
api = f"api/test/agents/{userName}"
url = product + api
payload = {
"email" : f"{userName}@test.com",
"password": f"{passwd}",this continues to do some api call ^
i tried to add split() at the end of the input but it didnt help, please advise how to do such an action