G+_Brandon Ingli Posted May 10, 2014 Share Posted May 10, 2014 New discovery that I thought I would pass on. You can pull characters out of strings by position like you can an item in a list. For example: name = "brandon" print name[1] Output: >>> r Link to comment Share on other sites More sharing options...
G+_L I Posted May 10, 2014 Share Posted May 10, 2014 You can also do slices like a list print name[2:5] # outputs "and" Link to comment Share on other sites More sharing options...
G+_Darryl Medley Posted May 10, 2014 Share Posted May 10, 2014 Strings work like a list of characters in a lot of ways. You can use loops: for ltr in "Some String": print ltr Link to comment Share on other sites More sharing options...
G+_Joe Maruschek Posted May 10, 2014 Share Posted May 10, 2014 Try negative numbers. They count from the end of the string! print name[-1] # outputs "n" print name[-2] # outputs "o" Link to comment Share on other sites More sharing options...
Recommended Posts