DIFFERENCE BETWEEN APPEND AND EXTEND IN PYTHON - TIC TECH TECH

EVERYTHING YOU NEED TO KNOW ABOUT

Breaking

Thursday, August 31

DIFFERENCE BETWEEN APPEND AND EXTEND IN PYTHON

Extend AND Append  :

APPEND

Append is used to add one element at the end of the existing list.For example if we have two list named li and x such that so it will increment the length of existing list by +1 only .

Sample code for append to understand better 
>>> li=[1,2,3]
>>> x=[4,5,6]
>>> li.append(x)
>>> li
[1, 2, 3, [4, 5, 6]]
>>> len(li)
4
Python Code snippet of the above code








Extend

Extend is used when we have to merge two list extend will iterate through the passed argument and add them to the existing list at a index of i+1,i+2,i+3…(where n is existing length of the list)


Sample code for append to understand better 



>>> li=[1,2,3]
>>> x=[4,5,6]
>>> li.extend(x)
>>> li
[1, 2, 3, 4, 5, 6]
>>> len(li)
6
>>> 

Python Code snippet of the above code 














Thank you for reading for any query you can comment below
















2 comments:

  1. I know a real professional hacker who has worked for me twice in the past one month. He is very good at hacking anything concerning database, phone, social media and even credit report fixes. He offers legit services. He also helps to retrieve accounts that have been taken by hackers. Contact him at cybergoldenhacker at gmail dot com

    ReplyDelete

  2. Hi, everyone, I'm recommending a great, truth professional hacker that assisted me when I needed funds desperately. I was introduced to him by a friend he had already helped. I hired his service for pay pal transfer and bank transfer to my wells Fargo bank. Contact him for bank transfer, pay pal transfer, bit-coin transfer, social network hack, social network verification (blue badge) etc. He is the most trusted hacker out there. Contact: cybergoldenhacker at gmail dot com

    ReplyDelete

Post Top Ad