Python List Brief
1.What is Python List and How
Can we Create it?
So python list is type of
array data type we denote its via square brackets like this [ ]
Inside it any data type like
int, float, str etc we can store it .
List help us to storing large
no. of data via sequence wise ,Python list is the easy way to creating array in
python and use it as per requirements , Python list are mutable means we can
change the data inside the list whenever
we want , list is ordered and its also
allow duplicates elements.
Syntax
listname = [“Item1”, “item2”, “item3”]
print(listname)
Some built-in python method
for list
·
Append
method –
With this
method we can add new data or element inside list
·
Extend
method –
With this method we can
combine two list into one
·
Index
method-
With this
method we can check specific elements index position
Etc.
How can we use for loop with
python list?
We can use python for loop
with list for traversing every element separate or print full list here we use it for print separate element in every
line.
Syntax
listname = [“Item1”, “item2”,
“item3”]
for i in range(0,
len(listname)):
print(listname[i])
or we can
Syntax
listname = [“Item1”, “item2”, “item3”]
n = len(listnam)
for i in range(0,n):
print(listname[i])
here “n” is size of length of
list
How can we extend list?
We have to make two seprate
list and than we using extend method to combine list2 into list1 and than we
print list2
Syntax
list1 = ["Item1",
"item2", "item3"]
list2 = ["item4",
"item5", "item6"]
list2.extend(list1)
print(list2)
Put Your Thought or Query Here