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


    #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')


  • 相关阅读:
    疲劳原理
    golang中的 time 常用操作
    access与excel
    数据结构正式篇!初探!!
    数据结构复习之C语言malloc()动态分配内存概述
    C语言字符数组与字符串
    数据结构复习之C语言指针与结构体
    c语言数组
    数据结构
    C语言腾讯课堂(一)
  • 原文地址:https://www.cnblogs.com/lkpp/p/7400055.html
Copyright © 2020-2023  润新知