1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
g='''Eminem-Not Afraid (Hook:(Intro:) I'm not afraid (Yeah) to take a stand (It's been a ride) Everybody (I guess i had to) come take my hand (go to that place) We'll walk this road together(to get to this one) through the storm (Now some of you) Whatever weather,cold or warm (might still be in that place) Just to let you know that(If you're trying to get out) you're not alone (just follow me) Holla if you feel that you've been down the same road (I'll get you out) (Verse 1) You can try and read my lyrics off of this paper before I lay them But you won't take the sting out these words before I say them Cause ain't no way I'm let you stop me from causing mayhem When I say them or do something I do it I don’t give a damn. What you think I'm doing this for me So fuсk the world,feed it beans, it's gassed up If a thing's stopping me I’mma be what I set out to be, without a doubt undoubtedly And all those who look down on me I'm tearing down your balcony No if ands or buts don't try to ask him why or how can he From Infinite down to the last Relapse album he’s still shit and Whether he's on salary, paid hourly Until he bows out or he shits his bowels out of him Whichever comes first, for better or worse He's married to the game like a fuсk you for christmas His gift is a curse forget the earth he's got the urge To pull his dick from the dirt and fuсk the universe (Hook) I'm not afrai to take a stand Everybody come take my hand We'll walk this road together through the storm Whatever weather cold or warm Just let you know that you're not alone Holla if you feel that you've been down the same road (Verse 2) Ok quit playing with the scissors and shit, and cut the crap I shouldn't have to rhyme these words in the rhythm for you to know it's a rap You said you was king you lied through your teeth For that fuck your fillings instead of getting crowned you're getting capped And to the fans, I'll never let you down again, I'm back I promise to never go back on that promise, in fact Let's be honest, that last Relapse CD was 〃ehhhh〃 Perhaps I ran them accents into the ground Relax, I ain't going back to that now All I'm tryna say is get back, click-clack BLAOW Cause I ain't playing around There's a game called circle and I don't know how I'm way too up to back down But I think I'm still tryna figure this crap out Thought I had it mapped out but I guess I didn't This fucking black cloud's still follows me around But it's time to exercise these demons These motherfuckers are doing jumping jacks now! (Hook) I'm not afraid to take a stand Everybody come take my hand We'll walk this road together through the storm Whatever weather cold or warm Just let you know that you're not alone Holla if you feel that you've been down the same road (Bridge) And I just can't keep living this way So starting today I'm breaking out of this cage I'm standing up, Imma face my demons I'm manning up, Imma hold my ground I've had enough, now I'm so fed up Time to put my life back together right now (Verse 3) It was my decision to get clean, I did it for me Admittedly i probably did it subliminally for you So I could come back a brand new me, you helped see me through And don't even realize what you did, believe me you I been through the ringer,but they can do little to the middle finger I think I got a tear in my eye,I feel like the king of My world,haters can make like bees with no stingers,and drop dead No more beef flingers, no more drama from now on, I promise To focus solely on handling my responsibilities as a father So I solemnly swear to always treat this roof like my daughters and raise it You couldn't lift a single shingle lonely Cause the way I feel I'm strong enough to go to the club Or the conner pub and liftthe whole liquor counter up Cause I'm raising the bar I shoot for the moon But I'm too busy gazing at stars I feel amazing and (Hook) I'm not afraid to take a stand Everybody come take my hand We'll walk this road together through the storm Whatever weather cold or warm Just let you know that you're not alone Holla if you feel that you've been down the same road LRC by:Jack·Rogesion QQ:125287385''' g=g.lower() // 小写 g=g.replace(',',' ') // ,改为' ' g=g.replace('.',' ') //.改为' ' g=g.split(' ') 分隔 g.count('something') 统计个数 print(g)
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
f=list('221211322313212222132') f.append('2') //添加 f.pop(0) //删除 f.insert(3,'3') // 插入 list(range(5)) //遍历 f.index('3') //第一个3分下标 f.count('1') //1分同学的个数 f.count('3') //3分中学的个数
3.简要描述列表与元组的异同。
列表创建后可以通过语句修改,元组创建后不可修改。列表十分相似,不过元组是不可变的。即你不能修改元组。元组通过圆括号中用逗号分隔的项目定义。
元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。元组可以嵌套。