鱼C论坛

 找回密码
 立即注册

【Python学习笔记】统计字母数字空格等个数

已有 482 次阅读2016-12-21 15:06

自编代码:
def count_para(*param):
    coun = 0
    for i in param:
        coun += 1
        num = 0; alph = 0; space = 0; other = 0
        for j in list(i):
             asc = ord(j)
             if 47<asc<58: num += 1
             elif 64<asc<91 or \
                  96<asc<123: alph += 1
             elif asc == 32: space += 1
             else:other += 1
        print 'The no.',coun,'string has',num,'number,',\
              alph,'letter,',space,'space and',other,'other letter.'

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-6 18:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部