码迷,mamicode.com
首页 > 编程语言 > 详细

python预习-第四节

时间:2017-06-24 18:25:01      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:列表   instance   pytho   整数   lis   oat   img   4.4   bsp   

#遍历列表所有元素
技术分享

#!/usr/bin/python
# -*- coding: UTF-8 -*-

listm=["s","l","z","x","l","m","XX",[123,23,4,89,05,[78,35,65,2017],"zX",1.2],2.3,4.5,6.7,8.9,120.23,34.45]
int_num = 0
float_num = 0
letter_num = 0
for i in listm:
if isinstance(i,list):
for j in i:
if isinstance(j,list):
for m in j:
if isinstance(m,int):
int_num=int_num+1
elif isinstance(m,float):
float_num=float_num+1
elif isinstance(m,str):
letter_num=letter_num+1
elif isinstance(j,int):
int_num=int_num+1
elif isinstance(j,float):
float_num=float_num+1
elif isinstance(j,str):
letter_num=letter_num+1
elif isinstance(i,int):
int_num=int_num+1
elif isinstance(i,float):
float_num=float_num+1
elif isinstance(i,str):
letter_num=letter_num+1
print int_num
print float_num
print letter_num
print "see you my baby !!!!"

 

#统计列表中整数、小数、字母的个数

技术分享
#!/usr/bin/python
# -*- coding:UTF-8 -*-
listw =[1,2,3,4,5,6,8,1.3,2.3,4.5,9.0,2.67,"a","b","c","d","e",3.45,6.78,90,19,"hm"]
int_num=0
float_num=0
letter_num=0
for i in listw:
if isinstance(i,int):
int_num=int_num+1
elif isinstance(i,float):
float_num=float_num+1
elif isinstance(i,str):
letter_num=letter_num+1
print int_num
print float_num
print letter_num

 

python预习-第四节

标签:列表   instance   pytho   整数   lis   oat   img   4.4   bsp   

原文地址:http://www.cnblogs.com/dorothy-46/p/7073773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!