Python Forum
check if value of passed variable has uppercase characters in it.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check if value of passed variable has uppercase characters in it.
#4
you shouldnt need to use regex for simple string checks.

Because str.lower() does not effect string'd digits, you can just check for upper
listname = ['ONE', 'two', 'Thr33', 'four', 'FiVe368']
  
for name in listname:
    if any(char.isupper() for char in name):
        print(name.lower())
    else:
        print("{} is good".format(name))
Output:
one two is good thr33 four is good five368
If you really had to check digit you could do that as well
listname = ['ONE', 'two', 'Thr33', 'four', 'FiVe368', '67', '245245']
  
for name in listname:
    if any(char.isdigit() or char.isupper() for char in name):
        print(name.lower())
    else:
        print("{} is good".format(name))
Output:
one two is good thr33 four is good five368 67 245245
Recommended Tutorials:
Reply


Messages In This Thread
RE: check if value of passed variable has uppercase characters in it. - by metulburr - Sep-01-2017, 05:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 354 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,551 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  detecting a generstor passed to a funtion Skaperen 9 3,627 Sep-23-2021, 01:29 AM
Last Post: Skaperen
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 10,296 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  how to modify a variable that is passed as parameter StefanL38 2 2,126 Dec-07-2020, 08:39 AM
Last Post: StefanL38
  check pandas variable type cools0607 3 6,697 Jun-12-2020, 09:28 AM
Last Post: buran
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,771 May-15-2020, 01:37 PM
Last Post: snippsat
  Python uppercase conversion conditions Jaypeng 7 2,997 Apr-29-2020, 11:24 AM
Last Post: jefsummers
  Check for a special characters in a column and flag it ayomayam 0 2,057 Feb-12-2020, 03:04 PM
Last Post: ayomayam
  Check for funny characters with a regexp bertilow 4 2,775 Jan-19-2020, 10:16 AM
Last Post: bertilow

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020