python-3.x - print(variable1.format(variable2)) 代码的逻辑是如何工作的?
问题描述
例子:
hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"
print(joke_evaluation.format(hilarious))
“.format”有什么作用?为什么我们在这里使用空的 {}(大括号)?当我运行这段代码时,它是如何打印 False 的?这段代码是如何工作的?
解决方案
格式化字符串时,您可以这样做
"sometext {}".format("whatever is supposed to be places at curly brackets place")
这使
"sometext whatever is supposed to be placed at curly brackets place"
什么是 False,你对 False 感到很有趣,python 会在形成时自动将其解析为字符串
推荐阅读
- node.js - Express JS 处理程序中的 res.send() 是否会自动调用 next()?
- python - AttributeError: 'RDD' 对象没有属性 'show'
- python - Zipline 基本数据
- git - 由于文件名太长的问题,无法签出 Mule 代码
- ethereum - Ropsten(以太坊测试网络)交易无法解决(仍待处理),使用 Web3js
- tfs - TFS2018:暂停和恢复后执行的并行构建
- java - Webstart 上的多个 JAR 应用程序
- javascript - 如何动态放大amchart地图
- mysql - 多日期时间列索引的最佳数据库解决方案
- java - 如何使用 spring-cloud-contract 获得上一个请求的响应