python - 收集列表中的单个变量
问题描述
list = [ "test1", "test2", "test3"]
我想将列表中的变量作为字符串分配给 x,每个新变量都会放在一起,但不会放在最后。我想"test, test2, test3"
我该怎么办?
解决方案
试试这个。只需添加列表中的所有字符串。还要避免使用关键字变量名称,例如list
.
output= ""
for item in myList:
if output == "":
output += item
else:
output += ', '
output += item
print(str)
推荐阅读
- javascript - 平滑增加一个变量
- php - Laravel:如何从动态 jquery 复选框中保存数据库
- msal - MSAL.JS Vanilla JavaScript SPA 示例 - 添加“extraScopesToConsent”时出错
- three.js - renderer.setSize 到底是做什么的?
- deep-learning - 解释用另一个模型作为参数实例化模型的概念?VGGFace(model='resnet50', include_top=False)
- unix - 如何将身份文件与 rsync 和隧道一起使用?
- list - 输入'列表
' 不是类型 'List 的子类型 >' of '函数结果' - java - 如何在 Context xml 文件中定义 Tomcat 中的 UserDatabase?
- javascript - 根据 ES6 中的值从数组中删除重复项
- reactjs - 如何等待子组件渲染