python - 如何在 Python 中打印带引号的字符串和变量?
问题描述
我需要在一行中完成。有 2 个标签:
Albert Einstein once said, "A person who never made a mistake never tried anything new."
编码
famous_person = "Albert Einstein"
message ='\t\tf{famous_person} once said, "A person who never made a mistake never tried anything new."'
print(message)
但f{}
我猜是行不通的:(
解决方案
你可以。将f
字符放在字符串之前,例如f'...{...}...'
,不是'f{...}'
。
famous_person = "Albert Einstein"
message =f'\t\t{famous_person} once said, "A person who never made a mistake never tried anything new."'
print(message)
'\t\tAlbert Einstein once said, "A person who never made a mistake never tried anything new."'
推荐阅读
- visual-studio-code - VS Code SSH 用户名不能包含字符\
- java - 我可以使用 Kafka 和 Apache Camel 作为 ActiveMQ 的替代品吗?
- python - 为什么当我使用带有 for 循环的切片时,它不会只循环切片的项目?
- javascript - 将图像添加到由其他两个数组构建的数组中?
- asp.net-core - 我们怎么知道哪个消息是针对rabbitmq中的哪个服务的
- nativescript - 如何使用新的工作流程生成 nativescript 插件压缩包?
- python - Docker 和 Django Rest Framework “意外断开连接”
- sharepoint-online - 使用 Power Automate 从 Project Online 任务项中检索资源名称
- mocha.js - 如何使用 c8 排除 *.spec.mjs?
- omniorb - sudo $OSSIEHOME/bin/cleanomni