Is it possible to add more than one item to a list at one time?

2

I wonder if it's possible to add more than one element to a list, for example:

a=[]
a.append('abóbora', 'banana', 'maçã')

or you will need to use three lines, for example:

a=[]
a.append('abóbora')
a.append('banana')
a.append('maçã')

Please answer me.

    
asked by anonymous 05.11.2017 / 02:42

2 answers

1

With the .append method you will not be able to place a sequence of values within a list. The correct method for entering a string is .extend , so it will look like this:

lista = []
lista.extend(('abóbora', 'banana', 'maçã'))
print(lista)

output:

['abóbora', 'banana', 'maçã']
    
05.11.2017 / 02:49
1

You can use the += operator to concatenate a list into another:

a = []
a += ['abóbora', 'banana', 'maçã']
print(a)

Output:

['abóbora', 'banana', 'maçã']
    
05.11.2017 / 14:41