Python converts a string to an array of methods. Share to everyone for your reference. The implementation method is as follows:
#-----------------------------------------# name:string_to_array.py# author:kevin harris# last Modified: 02/13/04# description:this Python script demonstrates # How to Modify a string by# converting it to an array# -----------------------------------------Import arraystr = ' My name is Kevin ' Print (' str = ' + str ') # We ' re not allowed to Modify strings # So we'll need to convert it to a# character array Instead...chararray = Array.array (' B ', str) # in the IGNMENTCHARARRAY[11:16] = Array.array (' B ', ' Jason ') # replacementstr = chararray.tostring () # Assignment back to the Strin G Objectprint (' str = ' + str) input (' \n\npress Enter to exit ... ')
Output Result:
str = My name is Kevinstr = My name was Jason press Enter to exit ...
Hopefully this article will help you with Python programming.