How to generate a random phone number using Python?
In this article, we will learn how to generate a random phone number using Python. In general, Indian phone numbers are of 10 digits and start with 9, 8, 7, or 6.
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. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
- We will use the random library to generate random numbers.
- The number should contain 10 digits.
- The first digit should start with 9 or 8 or 7 or 6, we will use randint() method.
- The remaining 9 digits will also be generated using the randint() method.
The generated random phone numbers would looklike: 9980231467 8726189362