Text-Summary:
- What is Text
The string type in Python is an immutable type.
Text, a matrix of characters, every single text can be indented and organized quickly.
- Basic Text manipulation
① parse the data and put the data into the structure inside the program;
② the data in some way into another similar form, the data itself has changed;
③ to generate new data
process one character at a time:
- Task
The string is processed with one character at a time.
- Solution Solutions
You can create a list of subkeys that are characters of a string.
The code is as follows:
>>> thelist = List ('thestring')>>>thelist['T','h','e','s','T','R','I','N','g']>>> forCharinchthelist:PrintChar thestring>>> Map (LambdaX:x*3, Thelist) ['TTT','HHH','Eee','SSS','TTT','RRR','III','nnn','GGG']
Conversion between character and character values
- Task
Convert a character to the corresponding Ascⅱ (ISO) or Unicode code, or to the contrary.
- Solution Solutions
Built-in Functions Ord and CHR:
>>> Ord ('a')97>>> chr'a '
If you want to convert a string into a list of values that contain individual characters, you might want to use the built-in map and ORD functions at the same time:
Print map (ord,'python') [112, 121, 116, 104, 111, 110]
If you want to create a string from a list that contains a character value, you can use the '. Join, map, and CHR
Print ". Join (Map (Chr,range (97,100))) ABC
Experience:
1. Programming skills more reference to others, will become their own
2. The more basic the more you should remember and consolidate
3. It is said that the system business 80% is the processing of characters, so carefully study it
4. Do not accumulate kuibu to thousands of miles