Append and Extend python list

Difference between Append() and Extend() when acting on a list

Consider myList

Append()

myList= ['a','3','d','t']

myList.append(['c','d'])

print(myList)

=============OUTPUT ===============

[ 'a' , '3' , 'd' , 't' , [ 'c' , 'd' ] ]

====================================

Extend()


myList= ['a','3','d','t']

myList.extend(['c','d'])

print(myList)

=============OUTPUT ===============

[ 'a' , '3' , 'd' , 't' , 'c' , 'd' ]

====================================

2 thoughts on “Append and Extend python list

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s