When defining a function
def test (* args)And when receiving multiple arguments, I think that it will be received as a tuple.
Here, if you specify a list that stores some numbers in the argument of the test method,
([5,6,4])It looks like this, but here on the method side
(5,6,4)If I want to, what should you do?
Since tuples are immutable, take the value for minutes from the list and try again.
argsI think you can do something like that.
I would appreciate it if you could tell me what kind of method can be considered in such a case.
Answer # 1
On the calling side
*I think it's normal to develop iterables.
def test (* args): print (args) lst = [5, 6, 4] test (* lst)
(5, 6, 4)
def test (* args)When preparing the argument definition, the intention is
test (4, 5, 6)
Is expected to be called.
On the other hand
[4, 5, 6]If you want to pass it to the original, it is a line that the caller will match it with * expansion.
On the other handFrom the caller's point of view, if "always pass a value based on one list", then * expansion is useless, in which case "the person who defined the function made a mistake". Become.
Such a function
def test (lst): "" " : param lst: Iterable containing int ...
It was more natural to define something like this.
Answer # 2
What about tuple ([5,6,4])?
Answer # 3
In general, list-to-tuple conversion can be done with the tuple () function.
l = [5,6,4] t = tuple (l) # t = (5,6,4)
- how to store in dict using python for loop
- how to extract and edit the rgb value of each pixel in an image (python)
- python - [chainer] valueerror: too many value to unpack (expected 2) i don't know what to do about the error
- python 3x - i want to change the value in the event function with valuechanged
- [ruby] i want to store the value read from a file in a constant as an array, but i don't know how to write it well
- python - i want to show the time series data of csv only more than a specific value
- python - how to remove django projects and web applications
- i want to pass a value to js after opening a link with c # or python
- i can't successfully store the data scraped by selenium using python in the list
- same definition for named tuple in python
- python - unable to add value to redis set
- python - i want to put a specific value in column c up to the top n values in column b when column a meets a specific conditio
- python - i want to calculate the total value and maximum value for each time zone that is pandas
- how to find the maximum value using for statement and if statement in python
- python - how to get the value of multiple lines&use the first number as a key
- how to pass the value entered in the [wxpython] dialog to the main window
- python - why does the value of loss function loss not decrease even if epoch is increased? ?
- please tell me how to get the value at once by specifying multiple arbitrary keys from the python json array
- i want to remove unicode with python regular expression
- python: about variable references
- about api authentication using python requests module
- i'm having trouble installing the python library from github
- python - i want to edit a py file using a virtual environment with vs code
- python - how to get child elements from the element obtained with bs4elementtag
- about python exponentiation
- python - how to make a non-rewritable array rewritable
- python - i want to go beyond double proxies with requesst
- python - i want to make a 4 * 4 square matrix by combining matrices with 4 elements
- python - appned to list becomes none type