top of page
Writer's pictureThe Tech Platform

Write a Python program to repeat specific Characters in String

Updated: Jul 2, 2022




To Repeat all the Characters

string = "thetechplatform"
n = 2
repeated_characters = ''.join([character*n for character in string])
print(repeated_characters)

Output:




To Repeat the Specific Character

def repeatSpecificCharacters(string,chars,n):
    for i in range(0,len(chars)):
        string = string.replace(chars[i], chars[i]*n[i])
    return string
print(repeatSpecificCharacters("thetechplatform","om",[3,4]))

Output:



The Tech Platform

Recent Posts

See All

Comments


bottom of page