There is a function shuffle in the random module. Note that it shuffles in-place so you first have to convert your string to a list of characters, shuffle it, then join the result again.
import random
l = list(s)
random.shuffle(l)
result = ''.join(l)
Please find the code below to shuffle the string. The code will take the string and convert that string to list. Then shuffle the string contents and will print the string.
import random
str_var = list("shuffle_this_string")
random.shuffle(str_var)
print ''.join(str_var)
Here is a helper that uses random to non-destructively shuffle, string, list or tuple:
def shuffle_any(o):
is_l=is_t=False
if isinstance(o, str):
l = list(o)
elif isinstance(o, list):
l = o[:]
is_l = True
elif isinstance(o, tuple):
is_t = True
l = list(o)
else:
raise Exception("o is None!" if o is None \
else f"Unexpected type: {o.__class__.__name__}")
random.shuffle(l)
return l if is_l else tuple(l) if is_t else ''.join(l)