Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to locate digits and capital letters in a Python string

Is there a way to locate capital letters and digits in a string?

Here is the code I have so far:

# Imports


import random

# Variables

my_score = 0
loop = True

# start

while loop == True:

  username = input("Enter your username")

  has_digit = False
  has_upper = False

I tried searching Google but I couldn’t find anything that seems to work, any ideas?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

import re

has_upper = True if re.search('[A-Z]', username) else False
has_digit = True if re.search('\d', username) else False
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading