运用python的函数式编程,并且要求应用到lambda表达式和使用map()函数,写一个程序,核心代码不少于三十行。
5条回答 默认 最新
- 漫伊 2022-05-28 15:48关注
获得0.80元问题酬金 实体类
class Person: name = '' age = 0 Date = '' id = '' def say_some(self): return f'我是克隆体:{self.name} 号,出生于 {self.Date}'
方法
# 获取 一个集合数据 from datetime import datetime def get_Person_List(name): arr = [] for x in range(0, 50): # 循环50 次 ser = '_{:0>3d}'.format(x + 1) # 格式化3位数序号,位数不够0 补位 per = Person() per.id = x + 1 per.name = name + ser per.age = 13 per.Date = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f") # 格式化时间 per.say_some() arr.append(per) return arr def print_str(x): print(x.name) print(x.age) print(x.say_some()) # Press the green button in the gutter to run the script. if __name__ == '__main__': lst = get_Person_List('张三') list(map(lambda x: print_str(x), lst)) # 使用lambda 匿名函数,map() 返回迭代器,list()转换为列表
解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
- ¥20 关于URL获取的参数,无法执行二选一查询
- ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
- ¥15 marlin编译错误,如何解决?
- ¥15 有偿四位数,节约算法和扫描算法
- ¥15 VUE项目怎么运行,系统打不开
- ¥50 pointpillars等目标检测算法怎么融合注意力机制
- ¥20 Vs code Mac系统 PHP Debug调试环境配置
- ¥60 大一项目课,微信小程序
- ¥15 求视频摘要youtube和ovp数据集