0

Something incomprehensible when the code is executed, I don't know how to describe it, but the screenshot shows

Code:

symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
@client.event
async def on_message(message):

    if message.content.startswith('Код'):
        await message.channel.send(random.choice(symbols) for x in range(6))

Here you can see that the last 6 characters still change, but I do not understand how to remove unnecessary

enter image description here

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
369
  • 35
  • 2

1 Answers1

0

random.choice(symbols) for x in range(6) is a generator object: it gets evaluated lazily when you iterate over it.

(random.choice(symbols) for x in range(6)) is a generator too. The parentheses are required if you want to use it in an argument list or similar.

[random.choice(symbols) for x in range(6)] is a list.

list(random.choice(symbols) for x in range(6)) is too.

tuple(random.choice(symbols) for x in range(6)) is a tuple.

{random.choice(symbols) for x in range(6)} is a set.

If you want a string, you need to join the chosen characters into one:

''.join(random.choice(symbols) for x in range(6))

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264