Given a string in Python. The task is to check whether the string has at least one letter(character) and one number. Return “True” if the given string full fill above condition else return “False” (without quotes).
Input: welcome2ourcountry34 Output: True Input: stringwithoutnum Output: False
The approach is simple we will use loop and two flags for letter and number. These flags will check whether the string contains letter and number. In the end, we will take AND of both flags to check if both are true or not. Letters can be checked in Python String using the isalpha() method and numbers can be checked using the isdigit() method.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Ways to check if given string contains only letter
- Python Program to Removes Every Element From A String List Except For a Specified letter
- Python regex to find sequences of one upper case letter followed by lower case letters
- Python program to capitalize the first letter of every word in the file
- Python - Eliminate Capital Letter Starting words from String
- Count the number of times a letter appears in a text file in Python
- Python | Find longest consecutive letter and digit substring
- Iterative Letter Combinations of a Phone Number
- Python | Check if two lists have at-least one element common
- Python | Find the list elements starting with specific letter
- Python - Words with Particular Rear letter
- Python - Count of Words with specific letter
- Check if the binary representation of a number has equal number of 0s and 1s in blocks
- Capitalize first letter of a column in Pandas dataframe
- PyQt5 QSpinBox - Getting letter spacing type
- PyQt5 QSpinBox - Getting letter spacing
- PyQt5 QSpinBox - Setting letter spacing
- Check whether a number has consecutive 0's in the given base or not
- Check if a Thread has started in Python
- Python | Check if key has Non-None value in dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.