|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def count(x,y):
- alphaNUM=0
- numbers=0
- spaceNUM=0
- otherNUM=0
- for i in x:
- if i.isalpha():
- alphaNUM += 1
- elif i.isnumeric():
- numbers += 1
- elif i.isspace():
- spaceNUM += 1
- else:
- otherNUM += 1
-
- return ["第一个字符串共有:英文字母 %d"%alphaNUM "个,数字%d"%numbers "个,空格%d"%spaceNUM "个,其他字符%d"%otherNUM "个"]
复制代码 程序才写了一半想试试 能行就写下一半。在写完英文字母个数时运行不会报错
而写到这里写完就报语法错误 invalid syntax 红框标在引号 请问是什么问题?
- def count(x,y):
- alphaNUM=0
- numbers=0
- spaceNUM=0
- otherNUM=0
- for i in x:
- if i.isalpha():
- alphaNUM += 1
- elif i.isnumeric():
- numbers += 1
- elif i.isspace():
- spaceNUM += 1
- else:
- otherNUM += 1
- return [f"第一个字符串共有:英文字母 {alphaNUM}个,数字{numbers}个,空格{spaceNUM}个,其他字符{otherNUM} 个"]
复制代码
用f-string
|
|