To get started with python, enter a line of characters and count the number of English letters, spaces, and numbers in it. and print them out

Enter a line of characters and count the number of English letters, spaces, and numbers in it. and print them out

I'm a beginner, please give me some help.

import re
String1=str(input('输入一行字符串'))
#创建正则表达式
count = re.compile(r'\d')
word  = re.compile('[A-Za-z]')
symbol=re.compile(r'\s')
count1=len(count.findall(String1))
#利用findall找到正则表达式中匹配的所有字符串len用于计算个数
count2=count.findall(String1)
word1=len(word.findall(String1))
word2=word.findall(String1)
symbol1=len(symbol.findall(String1))
symbol2=symbol.findall(String1)
print("数字的个数是%s"%count1)
print("它们分别为%s"%count2)
print("字母的个数为%s"%word1)
print("字母是有%s"%word2)
print("空格的个数为%s"%symbol1)

Insert image description here

Guess you like

Origin blog.csdn.net/intellig_id/article/details/108567612