User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 423,637 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,176 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums

Starting Python

Join Date: Jan 2008
Posts: 591
Reputation: ZZucker is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 21
ZZucker's Avatar
ZZucker ZZucker is offline Offline
Posting Pro

Re: Starting Python

  #139  
Jun 28th, 2008
An interesting way to check if a letter is between A and Z:
  1. def has_cap(text):
  2. """return True if text contains a capital letter"""
  3. for ch in text:
  4. # character ch is between A and Z inclusive
  5. if 'A' <= ch <= 'Z':
  6. return True
  7. return False
  8.  
  9. text1 = 'the Good die young, Pricks live forever!'
  10. text2 = 'the good die young, pricks live forever!'
  11. print 'text1 =', text1
  12. print 'text2 =', text2
  13.  
  14. # test the function has_cap()
  15. if has_cap(text1):
  16. print "text1 has a capital letter"
  17. else:
  18. print "text1 has no capital letter"
  19.  
  20. if has_cap(text2):
  21. print "text2 has a capital letter"
  22. else:
  23. print "text2 has no capital letter"
Never argue with idiots, they'll just bring you down to their level and beat you with their experience.
Reply With Quote  
All times are GMT -4. The time now is 10:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC