#统计字符个数方法 def count_char(char,string): count=0 for c in string: if c==char: count+=1 return count char='l' string='hello world' count =count_char(char,string) print('{0}字符个数为:{1}'.format(char,count)) #判断三角形 def is_triangle(a,b,c): if a+b>c and abs(a-b)<c: return True else: return False print(is_triangle(2,3,1)) #水仙花判断 def is_narcissistic_num(num): count=0 for i in str(num): count=pow(int(i),3)+count if count==num: return True else: return False print(is_narcissistic_num(153))
标签:count,字符,片段,string,char,三角形,水仙花,def From: https://www.cnblogs.com/xiaokuangnvhai/p/18021515