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

What is the list data structure in Python?

A list is a collection that is ordered and changeable. In Python, lists are written with square brackets.
example:
mixed=[1,2,3,[4,5,6],‘seven’,8.0,9]
 

List odered in Python

mixed=[1,2,3,[4,5,6],‘seven’,8.0,9]

print(mixed[0]) # OutPut =1

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

What is the append method? with examples

The append() method appends an element to the end of the list. Now we will see how to add Add data to our list by using the append method.
mixed.append(10)
mixed.append([11,12,13])
print(mixed) 

What is extend() method in Python? with example

The extend() method adds the specified list elements (or any iterable) to the end of the current list. Now we will see the example to use of extend() method in python.

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

What is the join method in Python? with example

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

Syntax

The syntax to use the join method in python is given below:

string.join(iterable)

Example

Now we see the one of the simple Ways to concatenate two lists in Python

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

Recommended Post:

learn more about salesforce

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment