In Python, I can treat a string as a collection of characters and iterate through it without the need to do any sort of conversion on it, or muck about with "substr" ...
breakfast = "Croissants and toast"
for letter in breakfast:
print "Give me a ",letter
print "and we have",breakfast
Dorothy-2:py grahamellis$ python sar2
Give me a C
Give me a r
Give me a o
Give me a i
Give me a s
Give me a s
Give me a a
Give me a n
Give me a t
Give me a s
Give me a
Give me a a
Give me a n
Give me a d
Give me a
Give me a t
Give me a o
Give me a a
Give me a s
Give me a t
and we have Croissants and toast
Dorothy-2:py grahamellis$ (written 2009-07-12)
Associated topics are indexed under
Y104 - Python - Lists and Tuples [4027] Collections in Python - list tuple dict and string. - (2013-03-04)
[3763] Spike solutions and refactoring - a Python example - (2012-06-13)
[3669] Stepping through a list (or an array) in reverse order - (2012-03-23)
[3348] List slices in Python - 2 and 3 values forms, with an uplifting example - (2011-07-06)
[3257] All possible combinations from a list (Python) or array (Ruby) - (2011-04-23)
[3181] Beware - a=a+b and a+=b are different - Python - (2011-02-23)
[3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
[2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12)
[2719] Traffic lights in Python - (2010-04-13)
[2368] Python - fresh examples of all the fundamentals - (2009-08-20)
[2280] Creating and iterating through Python lists - (2009-07-12)
[1789] Looking for a value in a list - Python - (2008-09-08)
[1641] Tektronix 4010 series / Python Tuples - (2008-05-13)
[1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
[955] Python collections - mutable and imutable - (2006-11-29)
[899] Python - extend v append on a list - (2006-10-20)
[657] The ternary operator in Python - (2006-03-25)
[383] Overloading of operators on standard objects in Python - (2005-07-19)
Y108 - Python - String Handling [3886] Formatting output - why we need to, and first Python example - (2012-10-09)
[3796] Backquote, backtic, str and repr in Python - conversion object to string - (2012-07-05)
[3469] Teaching dilemma - old tricks and techniques, or recent enhancements? - (2011-10-08)
[3468] Python string formatting - the move from % to str.format - (2011-10-08)
[3349] Formatting output in Python through str.format - (2011-07-07)
[3218] Matching a license plate or product code - Regular Expressions - (2011-03-28)
[3090] Matching to a string - what if it matches in many possible ways? - (2010-12-17)
[2814] Python - splitting and joining strings - (2010-06-16)
[2780] Formatted Printing in Python - (2010-05-25)
[2765] Running operating system commands from your Python program - (2010-05-14)
[2721] Regular Expressions in Python - (2010-04-14)
[2692] Flexible search and replace in Python - (2010-03-25)
[2406] Pound Sign in Python Program - (2009-09-15)
[1876] Python Regular Expressions - (2008-11-08)
[1608] Underlining in Perl and Python - the x and * operator in use - (2008-04-12)
[1517] Python - formatting objects - (2008-01-24)
[1195] Regular Express Primer - (2007-05-20)
[1110] Python - two different splits - (2007-03-15)
[970] String duplication - x in Perl, * in Python and Ruby - (2006-12-07)
[954] Splitting Pythons in Bradford - (2006-11-29)
[943] Matching within multiline strings, and ignoring case in regular expressions - (2006-11-25)
[903] Pieces of Python - (2006-10-23)
[773] Breaking bread - (2006-06-22)
[560] The fencepost problem - (2006-01-10)
[496] Python printf - (2005-11-15)
[463] Splitting the difference - (2005-10-13)
[324] The backtick operator in Python and Perl - (2005-05-25)
56d4
Some other Articles
Wiltshire Community Area PartnershipsLearning to program in Ruby - examples of the programming basicsNew to programming? It is natural (but needless) for you to be nervousGreat new diagrams for our notes ... Python releasesStrings as collections in PythonEveryone is in the customer relations businessChecking robots.txt from PythonPython - using exceptions to set a fallbackUnderstanding the new local government structure in Wiltshire