Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Python: Strings
1. Python: Strings
Strings in Python, like in languages such as JavaScript, Lua, etc., are not mutable.
Whenever a string is concatenated to another string, a third string is made from the copied strings.
Thus, if a big string is being constructed, one should not use string concatenation as this can be an expensive operation (if done a large number of times).
2. How not to construct big strings
Here is the Python code [#1]
Here is the output of the Python code.
3. How to construct big strings
Here is the Python code [#2]
Here is the output of the Python code.
4. Splitting a string to a list
A string can be split based on a text pattern.
Here is the Python code [#3]
Here is the output of the Python code.
Note: The strip method of the string object is used to insure there are no leading or trailing white space. This is not needed here, but may be needed in other applications.
Note: For more advanced splitting of strings, regular expression pattern matching can be used - a future topic.
5. End of page