471,325 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

compare 2 string

I have 2 strings

name1 = 'john smith'

name2 = 'John smith'

What command should I use to check whether name2 is a capitalized version of name1? (the return value is True)
Sep 14 '07 #1
3 9323
bvdet
2,851 Expert Mod 2GB
I have 2 strings

name1 = 'john smith'

name2 = 'John smith'

What command should I use to check whether name2 is a capitalized version of name1? (the return value is True)
Expand|Select|Wrap|Line Numbers
  1. >>> name1 = 'john smith'
  2. >>> name2 = 'John smith'
  3. >>> name1.lower() == name2.lower()
  4. True
  5. >>> import string
  6. >>> name2[0] in string.ascii_uppercase
  7. True
  8. >>> 
HTH
Sep 14 '07 #2
Expand|Select|Wrap|Line Numbers
  1. >>> name1 = 'john smith'
  2. >>> name2 = 'John smith'
  3. >>> name1.lower() == name2.lower()
  4. True
  5. >>> import string
  6. >>> name2[0] in string.ascii_uppercase
  7. True
  8. >>> 
HTH
Thank you very much. I figured out just a few hours ago.
Expand|Select|Wrap|Line Numbers
  1. name2==name1.capitalize()
  2.  
Very simple but I am an absolute beginner +_+
Sep 14 '07 #3
bartonc
6,596 Expert 4TB
Thank you very much. I figured out just a few hours ago.
Expand|Select|Wrap|Line Numbers
  1. name2==name1.capitalize()
  2.  
Very simple but I am an absolute beginner +_+
Yep. That's the way I went, too. But looking at bvdet's example, I see that it does a far more complete job of making sure that the case of all the letters are the same.
Sep 14 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by tvn007 | last post: by
2 posts views Thread by kw_uh97 | last post: by
10 posts views Thread by lovecreatesbea... | last post: by
7 posts views Thread by sigava77 via AccessMonster.com | last post: by
4 posts views Thread by ndoe | last post: by
6 posts views Thread by webmaniac | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.