Python列表操作自定义函数(二)

<span style="font-size:14px;"># -*- coding: cp936 -*-
#list函数形参传递
s = "www.baidu.com"
print s
li1 = list(s)
print 'li1',li1

#定义一个函数来剔除字符串中的.
def count_char(listchars):
    while "." in listchars:
        r = listchars.pop(listchars.index('.'))
        print r
    n = len(listchars)
    print 'there are no \'.\' in list'
    return n
new_char = count_char(li1)
print 'in %s has %d char' % (s,new_char)

def count_remove(listchars):
    while '.' in listchars:
        r = listchars.remove('.')
    else:
        print 'there are no \'.\' in list'
    n = len(listchars)
    return n
new_char1 = count_remove(li1)
print 'in %s has %d char' % (s,new_char1)


fw = open('E:\pythonRead.txt','a')
li2 = [1,2,3,4,12.3,'nihao','smile']
i = 0
while i <= len(li2) - 1:
    if isinstance(li2[i],int):
        fw.write(str(li2[i])+'\n')
    elif isinstance(li2[i],float):
        fw.write(str(li2[i])+'\n')
    else:
        fw.write(li2[i]+'\n')
    i = i + 1
fw.close
</span>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值