1 # st='hello kitty {name} is {age}' 2 # 3 # print(st.count('l')) # 统计元素个数 4 # print(st.capitalize()) # 首字母大写 5 # print(st.center(50,'#')) # 居中 6 # print(st.endswith('tty3')) # 判断是否以某个内容结尾 7 # print(st.startswith('he')) # 判断是否以某个内容开头 8 # print(st.expandtabs(tabsize=20)) 9 # print(st.find('t')) # 查找到第一个元素,并将索引值返回 10 # print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 待定:?:{} 11 # print(st.format_map({'name':'alex','age':22})) 12 # print(st.index('t')) 13 # print('asd'.isalnum()) 14 # print('12632178'.isdecimal()) 15 # print('1269999.uuuu'.isnumeric()) 16 # print('abc'.isidentifier()) 17 # print('Abc'.islower()) 18 # print('ABC'.isupper()) 19 # print(' e'.isspace()) 20 # print('My title'.istitle()) 21 # print('My tLtle'.lower()) 22 # print('My tLtle'.upper()) 23 # print('My tLtle'.swapcase()) 24 # print('My tLtle'.ljust(50,'*')) 25 # print('My tLtle'.rjust(50,'*')) 26 # print(' My tLtle '.strip()) 27 # print(' My tLtle '.lstrip()) 28 # print(' My tLtle '.rstrip()) 29 # print('ok') 30 # print('My title title'.replace('itle','lesson',1)) 31 # print('My title title'.rfind('t')) 32 # print('My title title'.split('i',1)) 33 # print('My title title'.title()) 34 35 36 #摘一些重要的字符串方法 37 #1 print(st.count('l')) 38 # print(st.center(50,'#')) # 居中 39 # print(st.startswith('he')) # 判断是否以某个内容开头 40 # print(st.find('t')) 41 # print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 待定:?:{} 42 # print('My tLtle'.lower()) 43 # print('My tLtle'.upper()) 44 # print(' My tLtle '.strip()) 45 # print('My title title'.replace('itle','lesson',1)) 46 # print('My title title'.split('i',1))
1 # a=list() 2 # print(a) 3 4 # dic={'name':'alex'} 5 6 # dic1={} 7 # dic2=dict((('name','alex'),)) 8 # print(dic2) 9 10 # dic3=dict([['name','alex'],]) 11 # print(dic3) 12 13 14 15
1 # ret2=dic1.setdefault('hobby','girl') 2 # print(dic1) 3 # print(ret2) 4 5 6 # dic3={'age': 18, 'name': 'alex', 'hobby': 'girl'} 7 # 8 # print(dic3['name']) 9 # 10 # print(list(dic3.keys())) 11 # print(list(dic3.values())) 12 # print(list(dic3.items())) 13 14 # li=[1,2,34,4] 15 # li[2]=5 16 # dic3={'age': 18, 'name': 'alex', 'hobby': 'girl'} 17 # dic3['age']=55 18 # print(dic3) 19 20 # dic4={'age': 18, 'name': 'alex', 'hobby': 'girl'} 21 # # dic5={'1':'111','2':'222'} 22 # dic5={'1':'111','name':'222'} 23 # 24 # dic4.update(dic5) 25 # print(dic4) 26 # print(dic5)
16 # dic1={'name':'alex'} 17 # dic1['age']=18 18 # print(dic1)
1 # dic5 = {'name': 'alex', 'age': 18, 'class': 1} 2 3 # dic5.clear() # 清空字典 4 # print(dic5) 5 # del dic5['name'] #删除字典中指定键值对 6 # print(dic5) 7 8 9 # print(dic5.pop('age')) #删除字典中指定键值对,并返回该键值对的值 10 # ret=dic5.pop('age') 11 # print(ret) 12 # print(dic5) 13 14 # a = dic5.popitem() #随机删除某组键值对,并以元组方式返回值 15 # print(a, dic5) 16 17 # del dic5 #删除整个字典 18 # print(dic5)