append() in Python

Configurare noua (How To)

Situatie

append() adds its argument as a single element to the end of a list. The length of the list increases by one.

Solutie

Pasi de urmat

 

my_list = [‘this’, ‘is’, ‘a’]
my_list.append(‘test’)
print my_list

 

Output:

[‘this’, ‘is’, ‘a’, ‘test’]

 

my_list = [‘this’, ‘is’, ‘a’, ‘test’]
another_list = [1, 0, 3, 2]
my_list.append(another_list)
print my_list

 

Output:

[‘this’, ‘is’, ‘a’, ‘test’, [1, 0, 3, 2]]

Tip solutie

Permanent

Voteaza

(5 din 9 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?