Exploring Bioinformatics with Python

Some Notes on Strings

Here are some string operations that you might find useful.

string[i]
Get the ith element of the string. Indices start at 0.
'Hello'[0] => 'H'
'Hello'[4] => 'o'
'Hello'[5] => An error!
list(string)
Convert a string to a list of characters.
list('Hello') => ['H', 'e', 'l', 'l', 'o']
string.join(list-of-strings, separator)
Join the elements of list-of-strings, putting separator between subsequent elements.

Note: To use the operations whose name begins with string, make sure to use import string.


This page was generated by Siteweaver on Thu Sep 10 09:37:01 2009.
The source to the page was last modified on Mon Aug 24 13:49:23 2009.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/ExBioPy/strings.html.

You may wish to validate this page's HTML

Samuel A. Rebelsky
rebelsky@grinnell.edu