Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

insert character into string at position x python

def ins(a,b,c):
    return a[:c]+b+a[c:]
a is original string
b is inserted character
c is position
#with error handling
def ins(a,b,c):
    if type(a)!=str:
      raise("TypeError: Ins takes first arg as a string.")
    elif type(b)!=str:
      raise("TypeError: Ins takes second arg as a string.")
    elif type(c)!=int:
      raise("Type error: Ins takes an int for position")
    return a[:c]+b+a[c:]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #insert #character #string #position #python
ADD COMMENT
Topic
Name
7+9 =