字符串
str1 = "abcddfg123456"
print(str1[0])
print(str1.find('ee'))
print(str1.index('a'))
str = '123'
new_str = str.center(10,"*")
print(new_str)
print(str.count("1"))
str1 = "135642282235"
print(str1.split("2",2))
str2 = str1.replace("2","*",2)
print(str2)
print(str1.startswith("1"))
print(str1.endswith("5"))
列表
test_list = [1, 2, 3]
test_list.append(4)
print(test_list)
test_list[3] = 5
test_list.insert(0, '0')
print(test_list)
test_list.remove('0')
print(test_list)
test_list.pop(0)
print(test_list)
print(test_list.index(5))
print(test_list.count(5))
test_list.sort()
print(test_list)
test_list_two = test_list.copy()
print(test_list_two)
new_list = test_list + test_list_two
test_list.extend(test_list_two)
print("===============")
print(new_list)
print(test_list)
print([i for i in range(10) if i % 2 ==0])
for ind, value in enumerate(test_list):
print(ind, value)
元组
tu = (1, 3, 4, 2)
print(tu.index(1))
print(tu.count(1))
集合
set_1 = {2, 3, 4, 5}
empt_set = set()
set_1.add('11')
set_1.update([6,7])
print(set_1)
set_1.remove(2)
set_1.discard('5')
print(set_1)
set_1.pop()
print(set_1)
set_1 = {1, 3, 4}
set_2 = {1, 3}
print(set_1.intersection(set_2))
print(set_1.union(set_2))
print(set_1-set_2)
print(set_1.difference(set_2))
字典
dict1 = {'a':'1', 'b':'2'}
print(dict1['a'])
print(dict1.get("c",None))
dict1['c'] = '3'
print(dict1)
dict1['c'] = '4'
print(dict1)
del dict1['c']
dict1.pop('b')
dict1.popitem()
print(dict1)
dict1 = {'a':'1', 'b':'2'}
for i in dict1:
print(i)
for k,v in dict1.items():
print(k, v)
print(list(dict1.keys()))
print(list(dict1.values()))