python - 我如何获得打印声明来告诉我作者的死亡日期?
问题描述
我试图让它说“作者”在“日期”中死亡,但它不起作用。
authors = {
"Charles Dickens": "1870",
"William Thackeray": "1863",
"Anthony Trollope": "1882",
"Gerard Manley Hopkins": "1889"
}
for author, date in authors.items():
print( "%s" % authors + " died in " + date)
解决方案
您只需将 print 中的变量名称从authors(您的完整字典)更改为author,代表集合的每个实例:
authors = {
"Charles Dickens": "1870",
"William Thackeray": "1863",
"Anthony Trollope": "1882",
"Gerard Manley Hopkins": "1889"
}
for author, date in authors.items():
print( "%s" % author + " died in " + date)
这会产生以下输出:
Charles Dickens died in 1870
William Thackeray died in 1863
Anthony Trollope died in 1882
Gerard Manley Hopkins died in 1889
推荐阅读
- javascript - 如何在 openssl 中解密使用 CryptoJs3+ 库加密的文件,并使用自定义迭代和密钥大小
- android - 始终在后台运行前台服务
- terraform - 如何从 vpc terraform 模块创建单个公共和私有路由表
- python - 根据另一个单元格中的字符串在 DataFrame 单元格的列表中插入值
- amazon-web-services - Redshift 数据库用户无权担任 IAM 角色
- c# - 以与非 API 异常不同的方式处理 API 异常。将代码移动到外部类库时出错
- amazon-web-services - 使用 Let's Encrypt 时,是否需要为 443 提供额外的 VirtualHost 条目?
- android - Android Studio 无法启动,原因是 Check Point 防病毒软件将 kotlin-stdlib.jar 移动到隔离区
- javascript - chart.js 折线图每 5 秒更新一次?
- azure - Azure - 集中管理客户端机密