Alterna · учебный материал

String Conversion

37.3: Line conversion: Short theory, one example, and Python stepway.

Что в этом материале

Содержание и основные понятия

Since the string is unalterable, conversion creates a new line: via replay, jone, or accumulation of parts in the list.
substance and practice
Grade 8
EEG No. 24
01
How it works.
The lines do not change the original line. Each method returns a new line or a list of parts that needs to be saved or passed on immediately.
Normalization.
strip, lower, and upper lead to a form that is convenient to compare.
Replacement.
Replace works from left to right and replaces non-overlapping fragments.
The breakup.
split creates a list of parts.
The assembly.
separator.join(parts) connects only the lines and places the divider between them.
02
One example in execution
Start the short program and go over the lines. The visualiser only shows the code, current line, variables and output.
split()
without an argument, divides the row according to sequences of blank symbols, tabs and lines;
split(' ')
Considers each gap as a separate divider and can give empty parts.
replace(old, new, count)
The third argument limits the number of replacements. In the substitution chain, order affects the total, so show the intermediate state in the mini-trass.
Algorithm map
Read from left to right, then run the code.
1
Start
2
Get the original line
3
Remove the edges and change the register
4
Replace Defiance
5
Delete old and new lines
03
Remember
Save the result of the method: s.upper() does not change s by itself.
Don't call join on the list: the divider is on the left of .join.
Check the order of two replays on a line where the new substrate is similar to the next target.
Syntax of this page
s.strip(chars=None)
Returns the row without the selected symbols on the edges; removes the blank symbols without an argument.
s.lower() / s.upper()
Return the row in the lower or upper register.
s.replace(old, new, count=-1)
Replaces non-crossable Old; default count = -1 means without restriction.
s.split(sep=None)
Breaks the line into a list of parts; behaviors without sep and with '' are different.
sep.join(parts)
Connects the string sequence through sep; all elements shall be str.
''.join(parts)
He's picking up pieces without a divider.
input / print
Read the original text and produce the converted result.

Structural map of textbooks