zoukankan      html  css  js  c++  java
  • 编写一个函数,分别统计出传入字符串参数的英文字符、空格、数字和其它字符的个数

    #coding = utf-8
    '''
    Created on 2015年5月31日
    '''
    
    def count(*params):
        '编写一个函数,分别统计出传入字符串参数的英文字符、空格、数字和其它字符的个数'
        param_count=0
        for each in params:
            param_count+=1
            letters=spaces=digits=others=0
            for each1 in list(each):
                if str.isdigit(each1):
                    digits+=1
                elif str.isspace(each1):
                    spaces+=1
                elif str.isalpha(each1):
                    letters+=1
                else:
                    others+=1
            print(('第%d个参数中有%d个英文字符,%d个空格,%d个数字,其它的%d个')%(param_count,letters,spaces,digits,others))
    
    count('hello world 123!','public static void main')


  • 相关阅读:
    函数特化
    模板函数总结
    学习代码1
    宏指令
    #define宏作用
    oracle 重要函数
    JMeter 系列之—-01 使用
    Selenium系列之--03 常见元素操作总结
    【转】TestNG常用注解
    CMMI 2,3,4,5级涉及的过程域(PA)介绍
  • 原文地址:https://www.cnblogs.com/lkpp/p/7400055.html
Copyright © 2011-2022 走看看