#!/usr/bin/python # string examples eggs = 'spam eggs' # use single quotes more_eggs = "more eggs" # double quotes are also ok print eggs, more_eggs err = 'it doesn\'t work' # escape if you want to include the single quote error = "it doesn't work" # or use double quotes print "err:",err print "error:",error multiLineString = """\ Usage: thingy [Options] -h display this message -H hostname hostname to connect to """ print multiLineString text = ('Put several strings within parentheses ' 'to have them joined together.') print text prefix='Py' postfix='thon' print prefix+postfix word = 'Python' print word[3] # get the nth letter in the string print word[2:5] # a sub string print word[:2] # everything before the 2nd letter # 2nd letter excluded print word[2:] # everyting after the second letter # 2nd letter included print word[:2] + word[2:]