Python‎ > ‎list‎ > ‎

list.append()

http://www.adilwaseem.com/

Definition
Add items to the list.

Syntax
L.append(object)

Parameters
String, numeric

Examples
The return with adding the list item to other.
list1=[222,333,444]
list2=[234,44,333]
list1.append(list2)
print(x)
>>> 
[222, 333, 444, [234, 44, 333]]
>>>

The return is:
 >>> a=['VA', 'DC', 'MD', 'NY']
>>> a.append('IL')
>>> a
['VA', 'DC', 'MD', 'NY', 'IL']
>>> 
>>> b=['TX', 'FL', 'CA']
>>> a.append(b)
>>> a
['VA', 'DC', 'MD', 'NY', 'IL', 'TX', ['TX', 'FL', 'CA']]
>>> 

str.split()->list.append()
The method convert the str to list and then append the item.
 >>> x="Python Lake"
>>> str.split(x)
['Python', 'Lake']
>>> type(['Python', 'Lake'])
<class 'list'>
>>> x.split()
['Python', 'Lake']
>>> z=x.split()
>>> z.append("Research Centre")
>>> z
['Python', 'Lake', 'Research Centre']


list.append(decimal)
The method list the decimal value and limit the decimal point to '1.00' through quantize.
from decimal import Decimal
list1=list()
list.append((Decimal(2.10).copy_negate().quantize(Decimal('1.00')),
                                 Decimal(1.3).copy_sign(Decimal(1.3)).quantize(Decimal('1.00')),
                                    Decimal(3).exp().quantize(Decimal('1.00')))
)
print("The items in the list1 are:,", list1)

>>> 
The items in the list1 are:, [(Decimal('-2.10'), Decimal('1.30'), Decimal('20.09'))]
>>>


Comments