{"id":24757,"date":"2021-11-02T09:45:58","date_gmt":"2021-11-02T04:15:58","guid":{"rendered":"https:\/\/python-programs.com\/?p=24757"},"modified":"2021-11-05T17:23:27","modified_gmt":"2021-11-05T11:53:27","slug":"python-list-extend-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-list-extend-method-with-examples\/","title":{"rendered":"Python List extend() Method with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python List count() method with Examples<\/a>
\nList in Python:<\/strong><\/p>\n

Lists in Python are mutable sequences. They are extremely similar to tuples, except they do not have immutability constraints. Lists are often used to store collections of homogeneous things, but there is nothing stopping you from storing collections of heterogeneous items as well.<\/p>\n

List extend() Method in Python:<\/strong><\/p>\n

The extend() method appends all iterable (list, tuple, string, etc.) items to the end of the list.<\/p>\n

Syntax:<\/strong><\/p>\n

gvnlist.extend(iterable)<\/pre>\n

All iterable elements are appended to the end of gvnlist in this case.<\/p>\n

Parameter Values:\u00a0<\/strong><\/p>\n

As previously stated, the extend() method accepts an iterable such as a list, tuple, string, and so on.<\/p>\n

Return Value:<\/strong><\/p>\n

The extend() method makes changes to the original list. It doesn’t return anything.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Main list = ['hello', 'this']\r\nGiven Second List = ['python', 'programs']<\/pre>\n

Output:<\/strong><\/p>\n

The Modified list after extending is :  ['hello', 'this', 'python', 'programs']<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Main list = ['hello', 'this']\r\nGiven Second Tuple= ('python', 'programs', 'python')<\/pre>\n

Output:<\/strong><\/p>\n

The Modified list after extending is :  ['hello', 'this', 'python', 'programs', 'python']<\/pre>\n

List extend() Method with Examples in Python<\/h2>\n