社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

用于格式化字符串的Python解包列表[重复]

Harry Lees • 5 年前 • 1460 次点击  

我有一个基于用户输入动态创建的字符串。我正在使用Python中的.format函数将列表添加到字符串中,但是我想在打印时删除引号和括号。

我试过:

return (('{} is {}x effective against {}').format(opponentType, overallHitMultiplier, [str(x) for x in playerTypes]))

return return (('{} is {}x effective against {}').format(opponentType, overallHitMultiplier, playerTypes))

两者都返回如下所示的字符串:

fighting is 2x effective against ['normal', 'ghost']

但我希望它返回如下内容:

fighting is 2x effective against normal, ghost

列表的长度是可变的,所以我不能一个接一个地插入列表元素。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52492
 
1460 次点击  
文章 [ 1 ]  |  最新文章 5 年前