A
A
Anton2021-10-28 05:06:33
Python
Anton, 2021-10-28 05:06:33

How to generate a string of this format in python?

Greetings!
Tell me how to generate such a string with random values: uppercase English letters and numbers 0-9
Format:
XXXX-XXXX-XXXX-XXXX-XXXX

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-10-28
@boypush

from random import choice

chars = '0123456789abcdefghijklmnopqrstuvwxyz'
section_size = 4
sections_num = 5

string = '-'.join(''.join(choice(chars) for j in range(section_size)) for i in range(sections_num))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question