Skip to content
Home » Select Random element from String : Python

Select Random element from String : Python

The random.choice() function chooses a character at random from a string. To select a random element from a string, use the code below.

# random.choice() method

# importing random module
import random

# prints random character from the given string
string1 = "similar"
print(random.choice(string1))

Output:

m

Also Read:

Select Random Element from List : Python