Python Random String And Number Mix

Function: create random string and number with length:

import random  
import string
len=10 #length of random string
def str_rand(len, chars=string.ascii_uppercase + string.digits):  
    return ''.join(random.choice(chars) for _ in range(len))  
print(str_rand(len))

Result:

EE5AJOGFIL

If you want shorter code:

rs=''.join(random.choices(string.ascii_uppercase + string.digits, k=len))  
print(rs)

Result:

62E9ALXY67

You can change chars= by other value to get other random string.
Example:

print(str_rand(3,chars='abcd123'))

Result:

ca1