473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

String comparisons

I am making a program that requires me to test whether a certain character in a string is capital. I was wondering if there was anyway I could do this like:

string is A-Z

That would determine whether the string is any letter from A to Z
Aug 20 '07 #1
8 1460
ilikepython
844 Expert 512MB
I am making a program that requires me to test whether a certain character in a string is capital. I was wondering if there was anyway I could do this like:

string is A-Z

That would determine whether the string is any letter from A to Z
Expand|Select|Wrap|Line Numbers
  1. >>> import string
  2. >>> 'g' in string.lowercase
  3. True
  4. >>> 'D' in string.lowercase
  5. False
  6.  
Aug 20 '07 #2
Expand|Select|Wrap|Line Numbers
  1. >>> import string
  2. >>> 'g' in string.lowercase
  3. True
  4. >>> 'D' in string.lowercase
  5. False
  6.  
Okay thanks, but is there a way to determine whether a letter is a vowel or not?
kinda like string=['a','e','i','o','u']
Aug 20 '07 #3
ilikepython
844 Expert 512MB
Okay thanks, but is there a way to determine whether a letter is a vowel or not?
kinda like string=['a','e','i','o','u']
Well...
Expand|Select|Wrap|Line Numbers
  1. >>> vowels = "aeiou"
  2. >>> 'e' in vowels
  3. True
  4. >>> 'f' in vowels
  5. False
  6.  
Aug 20 '07 #4
Well...
Expand|Select|Wrap|Line Numbers
  1. >>> vowels = "aeiou"
  2. >>> 'e' in vowels
  3. True
  4. >>> 'f' in vowels
  5. False
  6.  
Okay that makes sense now. But is there anyway to make it like a to z without typing each letter?
Aug 20 '07 #5
bartonc
6,596 Expert 4TB
Okay that makes sense now. But is there anyway to make it like a to z without typing each letter?
Expand|Select|Wrap|Line Numbers
  1. >>> from string import letters
  2. >>> "B" in letters
  3. True
  4. >>> 
Aug 20 '07 #6
Expand|Select|Wrap|Line Numbers
  1. >>> from string import letters
  2. >>> "B" in letters
  3. True
  4. >>> 
Okay excellent, thanks.
Aug 20 '07 #7
ghostdog74
511 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. >>> "B".isupper()
  2. True
  3. >>> "b".isupper()
  4. False
  5. >>> 
  6.  
Aug 20 '07 #8
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. >>> "B".isupper()
  2. True
  3. >>> "b".isupper()
  4. False
  5. >>> 
  6.  
Thanks, GD. Strings do have quite a few handy methods hung on them.
I also meant to point out that the string module is useful for the constants defined there, but the functions which are now string methods should not be used.
Aug 20 '07 #9

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

Similar topics

1
by: Monkey Steve | last post by:
Hi, I'm writing a website in asp.net(vb) with an access database behind it. As part of the site I have a table which has stores maximum and minimum values. These are integers at present. However...
6
by: Maileen | last post by:
Hi, I have the following code : Function GetRequestType(ByVal EvDt As String, ByVal StPeriod As String, ByVal EdPeriod As String, ByVal TaskType As String) As Integer Dim strtest As String Dim...
1
by: Dino Buljubasic | last post by:
Hi, I am using lots of string comparisons using String.StartsWith(subString) method where subString might be more than just couple of chars (e.g. "This is the string to compare ") I have...
4
by: Sjaakie | last post by:
I need to replace parts of a string, in a collection deserialized from an XML file, with values from another collection. Is there another, more clever/faster/better, method than the loops below? ...
4
by: Mark Rae | last post by:
Hi, Is it possible to create a case-insensitive List<stringcollection? E.g. List<stringMyList = new List<string>; MyList.Add("MyString"); So that:
2
by: Nishad | last post by:
Is anybody know how to write xpath for string Value Comparisons thank you
26
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I...
12
by: Merk | last post by:
What are some alternatives to using .ToUpper() to perform case insensitive string comparisons? The reason I'm asking is that I'm comparing strings in a long loop, looking for equality; and I...
14
by: Steve Bergman | last post by:
I'm looking for a module to do fuzzy comparison of strings. I have 2 item master files which are supposed to be identical, but they have thousands of records where the item numbers don't match in...
0
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.