a=[1,2,3]
b=["a","b","c"]
Something like that.
a=[1,2,3]
#.append()
a.ppend(4)
print(a)
Execution result
[1,2,3,4]
Add elements using append like this
a=[1,2,3,4]
#.remove()
a.remove(4)
print(a)
Execution result
[1,2,3]
Use remove like this to remove an element
a=[1,2,3]
print(a[0])
print(a[1])
print(a[2])
Execution result
1
2
3
The elements of the list are 0,1,2, ... from the left What happens from the right?
a=[1,2,3]
print([-1])
print([-2])
print([-3])
Execution result
3
2
1
The elements of the list are -1, -2, -3, ... from the right.
a=[1,2,3,4,5,6]
#1~Extract 3 elements
print(a[0:3])
#2~Extract 6 elements
print(a[1:])
#1~Take out every two elements of 6
print([::2])
Execution result
[1,2,3]
[2,3,4,5,6]
[1,3,5]
#There is a list in the list
a=[[1,2],[3,4],[5,6]]
print(a[0])
print(a[0][0])
text:Execution result:
#In the list of a[1,2]Taken out
[1,2]
#In the list of a[1,2]I took out the first one from the left of
1
Recommended Posts