str1=‘123456abcdefg’
def fun(str):
for i in range(0, len(str), 1):
print(str[i:i + 1], ‘/’, end=‘’)
fun(str1)
Output :
1 /2 /3 /4 /5 /6 /a /b /c /d /e /f /g /
Process finished with exit code 0
summary : The core of the short code is to disassemble the string and output
Then I read something else to say replace() The built-in functions are troublesome and can only replace specific characters
Another one spilt() function , yes
str.split(sep,maxsplit)
The meanings of the parameters in this method are respectively :
str: Represents the string to be split ;
sep: Used to specify separator , Can contain multiple characters . This parameter defaults to None, Indicates all empty characters , Including Spaces 、 A newline “\n”、 tabs “\t” etc. .
maxsplit: Optional parameters , Used to specify the number of divisions , The number of substrings in the final list is at most maxsplit+1. If not specified or designated as -1, It means that there is no limit to the number of segmentation .
This method is to move the string along the original space ( Or a specific character ) Open , After using regular expressions import re String can be split along multiple specified characters
For details, please refer to the link :
https://blog.csdn.net/sinat_38682860/article/details/80375369