Saturday, March 24, 2018

List extend( ) Method


List extend( ) Method

 The extend() method appends the contents of seq to list.

Syntax

list.extend(seq)

Parameters
  seq - This is the list of elements
Return Value
This method does not return any value but adds the content to an existing list.

Example

#!/usr/bin/python3

list1 = ['physics', 'chemistry', 'maths']
list2=list(range(5)) #creates list of numbers between 0-4
list1.extend('Extended List :', list2)
print (list1)

When we run the above program, it produces the following result-
Extended List : ['physics', 'chemistry', 'maths', 0, 1, 2, 3, 4]



<<< count( ) method                                   Go to Index                                index( ) >>>