|
|

学习笔记
- python函数练习
描点B
python函数练习
编写一个函数,要求实现一个给定字符串中的字母(大写或小写)以及数字的个数。
# coding:UTF-8
import sys # 导入sys模块
def stat(data):
result = dict(character=0, number=0) # 创建字典
foot = 0 # 操作脚标
for num in range(len(data)):
item = data[foot : foot + 1]
if (item >= "A" and item <= "Z") or (item >= "a" and item <= "z"):
result["character"] += 1
if item >= "0" and item <= "9":
result["number"] += 1
foot += 1
return result
def main():
print(stat("a1b2c3"))
if __name__ == "__main__": # 判断程序执行名称
main()
{'character': 3, 'number': 3}
|
|
最后
以上就是欢喜心锁最近收集整理的关于python函数练习-字符串中的字母(大写或小写)以及数字的个数python函数练习的全部内容,更多相关python函数练习-字符串中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复