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

1
  • @Tomerikoo. Done Commented Sep 9, 2021 at 18:59

1 Answer 1

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))

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.