作业

本文介绍了Python中列表和元组的基本概念及使用方法,并通过具体示例展示了如何利用列表进行数据处理,同时对比了列表与元组之间的异同。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.

s='''When I am down and oh my soul so weary 
When troubles come 
and my heart burdened be 
Then I am still and wait here in the silence 
Until you come and sit 
a while with me. 
You raise me up, so I can stand on mountains 
You raise me up, to 
walk on stormy seas 
I am strong, when I am on your shoulders 
You raise me up... 
to more than I can be 
You raise me upso 
I can stand on mountains 
You raise me up to walk on stormy seas 
I am strong, when 
I am on your shoulders 
You raise me up... 
to more than I can be 
You raise me up, so 
I can stand on mountains 
You raise me up 
to walk on stormy seas 
I am strong, when 
I am on your shoulders 
You raise me up... 
to more than I can be 
You raise me up, so 
I can stand on mountains 
You raise me up, to walk on stormy seas 
I am strong, when 
I am on your shoulders 
You raise me up... 
to more than I can be 
You raise me up... 
to more than I can be '''

s=s.lower()
for i in ',.?':
    s=s.replace(i,' ')
print(s.split(' '))
print(s.count('talk'))
print(s.count('anymore'))

 

2、列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

homework=list('134343633')
for i in range(len(homework)):
homework[i]=int(homework[i])
print(homework)
print(homework.index(6))
print(homework.count(1))
print(homework.count(3))

运行结果:

[1, 3, 4, 3, 4, 3, 6, 3, 3]
6
1
5

3、简要描述列表与元组的异同。

元组和列表十分类似,但是元组是不可变的.
也就是说你不能修改元组。
元组通过圆括号中用逗号分割的项目定义。
元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,
即被使用的元组的值不会改变。

转载于:https://www.cnblogs.com/lianghaohui123/p/7565482.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值