列表
实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
mu='''Hello, it's me,I was wondering if after all these years,You'd like to meet, to go over
Everything,They say that time's supposed to heal ya,But I ain't done much healing
Hello, can you hear me?I'm in California dreaming about who we used to be/When we were younger and free
I've forgotten how it felt before the world fell at our feet'''
mu=mu.lower()
for i in ',./?!':
print(mu.replace(i,' '))
words=mu.split('/')
print(words)
print('hello:',mu.count('hello'))
print('me:',mu.count('me'))
列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
简要描述列表与元组的异同。
列表是用[]表示,元组是();
列表能进行增删改,但元组不能;
tuple与list虽然非常相似,但是tuple一旦初始化就不能修改;
tuple与list是内置的有序集合,一个可变,一个不可变。