Test String Contents
Peter Otten
__peter__ at web.de
Tue Jun 13 18:50:37 EDT 2017
Matt wrote:
> What is easiest way to determine if a string ONLY contains a-z upper
> or lowercase. I also want to allow the "-" and "_" symbols. No
> spaces or anything else.
If you don't know regular expressions here's a method where not much can go
wrong:
>>> import string
>>> acceptable = frozenset(string.ascii_letters + "_-").issuperset
>>> acceptable("Foo-Bar")
True
>>> acceptable("Foo-Bar42")
False
>>> acceptable("Foo Bar")
False
>>> acceptable(string.ascii_letters + "_-")
True
More information about the Python-list
mailing list