小编qwi*_*qwi的帖子

并排打印 2 个列表

我正在尝试使用列表理解并排输出 2 个列表的值。我在下面有一个示例,显示了我正在尝试完成的工作。这可能吗?

代码:

#example lists, the real lists will either have less or more values
a = ['a', 'b', 'c,']
b = ['1', '0', '0']

str = ('``` \n'
       'results: \n\n'
       'options   votes \n'
       #this line is the part I need help with: list comprehension for the 2 lists to output the values as shown below
       '```')

print(str)

#what I want it to look like:
'''
results:

options  votes
a        1
b        0
c        0
''' 
Run Code Online (Sandbox Code Playgroud)

python

7
推荐指数
2
解决办法
2万
查看次数

Discord bot 命令列表

我有一个不和谐机器人的命令列表,所以我可以稍后更改或修改它们。当有人不和谐地编写命令时,我试图检查它是否在命令列表中。问题是我收到错误:

    for message.content.startswith in commands:
AttributeError: 'str' object attribute 'startswith' is read-only
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?我如何使它不是只读的……或者我将如何解决这个问题?


编码:

import discord, asyncio

client = discord.Client()

@client.event
async def on_ready():
    print('logged in as: ', client.user.name, ' - ', client.user.id)

@client.event
async def on_message(message):
    commands = ('!test', '!test1', '!test2')

    for message.content.startswith in commands:
        print('true')

if __name__ == '__main__':
    client.run('token')
Run Code Online (Sandbox Code Playgroud)

python-3.x discord

-2
推荐指数
1
解决办法
1254
查看次数

标签 统计

discord ×1

python ×1

python-3.x ×1