python-3.x - Python3 - 打印字符串和列表
问题描述
是否可以将下面的代码写得更短,一行?
print("Start line ", end="")
print(*list, sep=", ", end="")
print(" end of line.")
解决方案
print
您可以在以下帮助下尝试使用单个呼叫join
:
list = ['one', 'two', 'three']
print("Start line [" + ", ".join(list) + "] end of line.", end="")
Start line [one, two, three] end of line.
推荐阅读
- excel - 为什么 LibreOffice base、Microsoft Excel 和 Tableau 需要不必要的权限才能从 bigquery 查询表数据?
- eclipse-rcptt - RCPTT:获取产品安装路径的 ECL 命令
- php - Laravel 如何为 where like 查询动态数组列名称?
- scala - 不推荐使用 ReactiveMongo 中的方法 find 。0.20.3
- pandas - 比较熊猫不同数据框中的两列
- reactjs - useEffect 模拟 componentWillUnmount 不返回更新状态
- c# - 如何解决“/”应用程序索引未初始化中的服务器错误?
- python - 无法将 Django 模型导入 Python shell
- javascript - 如何使用 express-validator 对嵌套对象进行验证
- react-native - eslint@6.8.0:引擎“节点”与此模块不兼容。预期版本“^8.10.0 || ^10.13.0 || >=11.10.1”。得到“11.6.0”