Find Phone Number From Paragraph in Python

Find Phone Number From Paragraph in Python


Hello buddy! I’m new in Python and learning the Python from Institute of Nanasoft Technology and today the teacher tough me that how to Find Phone Number From Paragraph in Python and I decided to describe whatever I learn from the class that is why today I’m here for disclosing about it.

Find Phone Number From Paragraph in Python

If you really want to know how you can find the phone number which you added in the paragraph and now you are to find it out by python so, how will it be? I have been searching on Google to get the code but didn’t get even from the high sites such as StackOverflow either there have many experts of Python programming language but no one was there to describe this code.

Read more: iLock – iPhone Screen Lock APK Mod Unlock

Find Phone Number From Paragraph in Python

First, you are to make a variable of paragraph where you write the paragraph and place your number that must be having 11 or more than numbers or maybe less than if you are from Pakistan so, you don’t need to change the code of mine otherwise, you need to change if you belong to another country.

para = "This is demo num 786. some text. and this is my number 03332803015, 02788888888"

In the above variable I used two number I don’t know the numbers but I added whatever. You must need to consider it if you are making the software.

Now, use the for a loop after the para variable.

for count,i in enumerate(para)

Like above, for is keeping your value and checking to count it and then paste in I whatever for got the values and then enumerate is a built-in function, then I called the para which I made before.

Follow to the below code for closing this topic.

for count,i in enumerate(para):
     if(i.isdecimal()):
         l=len(para[count:count+11])
         d=para[count:count+11]
         if(l==11 and d.isdecimal()):
             print("Yes, Number found ",(para[count:count+11]))

Okay! I hope you understood the above code.

I’m going to again repeat from the starting.

para = "This is demo num 786. some text. and this is my number 03332803015, 02788888888,"

 for count,i in enumerate(para):

     if(i.isdecimal()):
         l=len(para[count:count+11])
         d=para[count:count+11]
         if(l==11 and d.isdecimal()):

             print("Yes, Number found ",(para[count:count+11]))

After printing all values then you can add 100+ numbers to find and more.

I have found the number from a paragraph in Python now you have to consider on the code.

I hope you got something from my article. Thanks for visiting.


Leave a Comment