How to insert char to string at specific index in Python

1 Answer

0 votes
def insertChar(s, char, index):
  return s[:index] + char + s[index:]
  

s = "python"
char =  'X'
index = 3

s = insertChar(s, char, index)

print(s)




'''
run:

pytXhon

'''

 



answered Sep 1, 2021 by avibootz

Related questions

1 answer 178 views
1 answer 191 views
1 answer 189 views
1 answer 300 views
1 answer 210 views
...