Chapter 6


1.

Strings

find(), rfind(), index(), rindex(); can also use the in operator.

2.

Identifiers

import string alphas = string.letters + '_' alnums = alphas + string.digits iden = raw_input('Identifier to check? ') if len(iden) > 0:      if iden[0] not in alphas:          print "Error: first char must be alphabetic"      else:           if len(iden) > 1:                for eachChar in iden[1:]:                     if eachChar not in alnums:                          print "Error: others must be alnum"                          break                else:                     import keyword                     if iden not in keyword.kwlist:                          print 'ok'                     else:                          print 'Error: keyword name' else:      print 'Error: no identifier entered'




Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net