Python StringSee a list of methods that can be used on strings. Review string literal syntax.
String. The forest air is cold. Suddenly an owl appears and perches on a log. It drops a message and flies away. You take the paper and find it has string data on it.
With a for-loop, we can iterate over the characters in a string. In loops we can use "in" or the range() built-in.String: for
We take substrings with the slice syntax. No substring method exists. We cannot assign a slice in a string, but we can concatenate slices together.String: SubstringString: Right
Often we have one-character strings. We can convert these strings into integers with ord. And with chr we convert an integer to a 1-char string.ord, chr
This is a helpful module included with Python. Textwrap offers a line-breaking algorithm. This can help with console output.Textwrap
There is no one way to parse HTML. A popular approach is to use the html.parser module. From it, we access the HTMLParser type. We build a class that inherits from HTMLParser.HTMLHTML: Remove HTML TagsXML
These are one kind of string algorithm. They change the values of characters in a string. One common cipher is the ROT13 algorithm.Cipher: ROT13Cipher: Caesar
Reverse, sort letters.
A string can be sorted and reversed. We use list comprehension on the string to get a list of its characters. And then we can use sort() or reverse().Letters: ReverseLetters: Sort
This is a buffer that can be used to quickly generate a large string. In my benchmarks, StringIO is faster for appending many strings in a loop.StringIO
In Python (as in all computer languages) we represent letters with numbers. This is a system called ASCII. We can generate an ASCII table with Python.ASCII Table
String handling, lists.
Python makes string handling simple. It considers text handling one of its core purposes. Strings are often used in lists.String List
Strings are great. But Python also introduces regular expressions for textual processing. These text expressions are best used for complex pattern-matching.
© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to firstname.lastname@example.org.