Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a random string with symbols

My code:

import random
import string
random = ''.join([random.choice(string.ascii_letters + string.digits ) for n in range(12)])

So far it prints a string which contains uppercase, lowercase letters and numbers, but I don't know how to make it print symbols as well.

like image 671
computing245 Avatar asked Dec 13 '22 20:12

computing245


2 Answers

How about:

import random
import string
random = ''.join([random.choice(string.ascii_letters + string.digits + string.punctuation ) for n in range(12)])
like image 150
Luke Smith Avatar answered Dec 28 '22 19:12

Luke Smith


Try:

import random
import string
random = ''.join([random.choice(string.ascii_letters + string.digits  ) for n in 
range(12)])
print(random)`
like image 29
Mayur Kachare Avatar answered Dec 28 '22 20:12

Mayur Kachare