# coding:utf-8
animals = ['小猫', '小狗', '龙猫', '小猫', '鹦鹉', '小狗', '小兔子', '小猫']
cat = animals.count('小猫')
dog = animals.count('小狗')
l_cat = animals.count('龙猫')
rabbit = animals.count('小兔子')
print('我家的院子里有很多小动物')
print('其中小猫有 %s 只' % cat)
print('小狗有 {} 只'.format(dog))
print(f'龙猫有 {l_cat} 只')
print('小兔子有 %d 只' % rabbit)
print('我们没有小松鼠, 所以松鼠有 %s 只' % animals.count('松鼠'))
animals_dict = [
{'name': 'dog'},
{'name': 'dog'},
{'name': 'cat'}
]
dog_dict_count = animals_dict.count({'name': 'dog'})
print('小狗在动物的字典中有%s只' % dog_dict_count)
animals_tuple = ('小猫', '小狗', '龙猫', '小猫',
'鹦鹉', '小狗', '小兔子', '小猫')
cat = animals_tuple.count('小猫')
dog = animals_tuple.count('小狗')
l_cat = animals_tuple.count('龙猫')
rabbit = animals_tuple.count('小兔子')
print('其中小猫有 %s 只\n小狗有 %s 只\n龙猫有 %s 只\n小兔子有%s只'
% (cat, dog, l_cat, rabbit))
没有合适的资源?快使用搜索试试~ 我知道了~
列表pythonlist.zip
共18个文件
py:12个
xml:5个
iml:1个
需积分: 5 0 下载量 144 浏览量
2022-11-06
00:28:04
上传
评论
收藏 10KB ZIP 举报
温馨提示
列表pythonlist.zip
资源推荐
资源详情
资源评论
收起资源包目录
列表pythonlist.zip (18个子文件)
列表-python_list
list_01.py 413B
str_index.py 131B
list_remove.py 757B
list_clear.py 131B
list_append.py 265B
list_count.py 1KB
list_sort.py 675B
list_index.py 727B
list_reverse.py 352B
.idea
codeStyles
codeStyleConfig.xml 149B
misc.xml 199B
modules.xml 274B
workspace.xml 8KB
inspectionProfiles
profiles_settings.xml 174B
python_list.iml 331B
list_insert.py 689B
list_copy.py 496B
list_extend.py 383B
共 18 条
- 1
资源评论
瑞瑞687
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功