Python: Where a string will start with a specific number
Python Regular Expression: Exercise-15 with Solution
Write a Python program that starts each string with a specific number.
Sample Solution:
Python Code:
import re
def match_num(string):
text = re.compile(r"^5")
if text.match(string):
return True
else:
return False
print(match_num('5-2345861'))
print(match_num('6-2345861'))
Sample Output:
True False
Pictorial Presentation:
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to match a string that contains only upper and lowercase letters, numbers, and underscores.
Next: Write a Python program to remove leading zeros from an IP address.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/re/python-re-exercise-15.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics