第三次
#(1)遍历列表 print('列表的遍历:') a=[1,2,3]; for i in a: print(i); #(2)遍历元组 print('元组的遍历:') a=(4,5,6); for i in a: print(i); #(3)遍历集合 print('集合的遍历:') a={7,8,9} for i in a: print(i); #(4)遍历字典 print('字典的遍历:') a={"姓名":"唐僧洗头爱飘柔","性别":"男","学号":123456789}; for key in a.keys(): print(key,":",a.get(key));
str2='''Cry on my shoulder If the hero never comes to you If you need someone you re feeling blue If you re away from love and you re alone If you call your friends and nobody s home You can run away but you can t hide Through a storm and through a lonely night Then I show you there s a destiny The best things in life They re free But if you wanna cry Cry on my shoulder If you need someone who cares for you If you re feeling sad your heart gets colder Yes I show you what real love can do If your sky is grey oh let me know There s a place in heaven where we ll go If heaven is a million years away Oh just call me and I make your day When the nights are getting cold and blue When the days are getting hard for you I will always stay here by your side I promise you I ll never hide What real love can do What love can do What real love can do '''.lower() print(str2) str2 = str2.replace('’',' ') str2 = str2.replace(':',' ') str2 = str2.replace(',',' ') str2 = str2.replace('.',' ') str2 = str2.replace('?',' ') str2 = str2.replace('!',' ') str2 = str2.replace('\n',' ') print(str2) str2 = str2.strip() str2 = str2.split(' ') print(str2.count("love")) print(str2)
bl = 'https://edu.cnblogs.com/campus/gzcc/14NetworkEngineering/homework/870' bl1 = bl.split('/') classmates = ['Michael', 'Bob', 'Tracy', '李三', 'Tracy'] print(classmates[-1]) print(classmates[1:3]) print(len(classmates)) print(max(classmates)) print(min(classmates)) print(classmates.index('Tracy')) print(classmates.count('Tracy')) classmates[1] = 'Sarah' print(classmates[1]) classmates.sort() # 没有返回值,改变列表本身 print(classmates) classmates.insert(1, 'Jack') print(classmates) classmates.append('Adam') print(classmates) classmates.extend(bl1) print(classmates) print(classmates.pop()) print(classmates.pop(1))