Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
3 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 (46k 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 (106k 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
+3 votes
2 answers
+3 votes
2 answers
asked May 24, 2019 in Python by Krishna (2.6k points)
0 votes
1 answer
asked Sep 10, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...