使用while循环实现输出2-3+4-5+6...+100 的和
for 循环
2、查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的所有元素。
li=["alec","aric","Alex","Tony","rain"]
tu=("alec","aric","Alex","Tony","rain")
dic={'k1':"alex",'k2':'aric',"k3":"Alex","k4":"Tony"}
1 li = ["alec", "aric", "Alex", "Tony", "rain"] 2 tu = ("alec", "aric", "Alex", "Tony", "rain") 3 dic = {'k1': "alex", 'k2': 'aric', "k3": "Alex", "k4": "Tony"} 4 5 list1 = list(tu) 6 list2 = list(dic.values()) 7 newlist = li + list1 + list2 8 for i in newlist: 9 ret = i.strip() #i.strip():删除字符串当前行首尾的的空格 10 if (ret.startswith('a') or ret.startswith('A')) and ret.endswith('c'): #startswith查看是否已什么开始,endswith查看是否已什么结尾 11 print(ret)
其中,startswith和endswith这两个语法在哪里学习的?