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:
- Python Hello World Program
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data , POP , popitem , update method
- Python Dictionary | update() method
- Delete statement , Looping in list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
learn more about salesforce