In Python, We have list and and dictionary, similarly as the container list and map in C++, follows are the list example.
>>>list = [i for i in range(8) if i%2==0]
>>>list
[0, 2, 4, 6]
>>>list.append(2)
>>>list
[0, 2, 4, 6, 2]
● Insert data:3 to index: 2
>>>list.insert(2, 3)
>>>list
[0, 2, 3, 4, 6, 2]
>>>list.remove(3)
>>>list
[0, 2, 4, 6, 2]
● Remove index:2
>>>del list[2]
>>>list
[0, 2, 6, 2]
● Find the count of a data:2
>>>list.count(2)
2
>>>6 in list
True
● Find length of a list
>>>len(list)
4
● Delete all contents in list
>>>del list[:]
>>>list
[]
【【【【 Advance 】】】】
● Collect sub string from a string
>>>s='123,234,456'
>>>b=s.split(',')
>>>b
['123', '234', '456']
● Combine list of string into a string
>>>c=','.join(b)
>>>b
'123,234,456'
沒有留言:
張貼留言