+3 votes
2 views
in Python by (10.2k points)

How can I generate a string of size N.

I want it to be of uppercase English letters and numbers like this:

  • 7I2D86
  • 5X5ILL
  • I022L5

How can I do it in Python. 

2 Answers

0 votes
by (46.1k points)
edited by

Just use random.sample , for instance look at this code:

import random
import string

char_set = string.ascii_uppercase + string.digits
print ''.join(random.sample(char_set*5, 5))

0 votes
by (107k points)

Use the below-mentioned code:-

import uuid

lowercase_str = uuid.uuid4().hex  

You can use the following video tutorials to clear all your doubts:-

Related questions

0 votes
2 answers
0 votes
1 answer
asked Sep 10, 2019 in Python by Sammy (47.8k points)
+1 vote
2 answers
+3 votes
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...