Using Python, I would like to be able to add multiple values/elements/items to a single list without having to repeat the .append method
Here is an example of what I mean. Review the following Python function:
singleList = []
def cal(rock):
singleList.append(rock)
singleList.append(input('Size: '))
singleList.append(int(input('Qty: ')))
print(singleList)
rock = cal(input('Rock: '))
Rock: granite
Size: small
Qty: 2
['granite', 'small', 2]
The -- singleList.append(list_element) -- statement must be repeated each time. Is it not possible to do something more like this:
singleList = []
def cal(rock):
singleList.append(rock), input('Size: '), int(input('Quantity: '))
print(singleList)
rock = cal(input('Rock: '))
...and still end up with:
['granite', 'small', 2]
Every way that I try to do this, I get the following error.
TypeError: append() takes exactly one argument (3 given)
I understand that .append() can only accept one argument, as per the error message. Is there an alternative way around this, or do people just repeat the .append() statement for each argument/element/value/item?
P.S. anyone know the correct term for: argument/element/value/item?