list is data structure , oder collection , Append method , Extend method , Join List , Python


list is data structure , oder collection , Append method , Extend method , Join List , Python
list

A list is a collection which is ordered and changeable. In Python lists are written with square brackets.
 
list is data structure
mixed=[1,2,3,[4,5,6],'seven',8.0,9]
 

list is oder collection

print(mixed[0])  # OutPut =1

print(mixed[3])    # OutPut =[4,5,6]

Add data to out list

Append method

 
The append() method appends an element to the end of the list.
mixed.append(10)

mixed.append([11,12,13])

print(mixed)
 

Extend method

 
The extend() method adds the specified list elements (or any iterable) to the end of the current list.
 

mixed.extend([14,15,16])

print(mixed)     
 
# Output = [1,2,3,[4,5,6],'seven',8.0,9,14,15,16]
 

Join List

 
The join() method takes all items in an iterable and joins them into one string.
 
A string must be specified as the separator.
 
 
 
Syntax
 
string.join(iterable)

l1=[1,2,3]

l2=[4,5,6]
 
l = l1 + l2

print(l)          #OutPut = [1,2,3,4,5,6]

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories