You can download this code by clicking the button below.
This code is now available for download.
This function uses the Mimesis library's Person module to generate a random phone number and formats it based on the country code.
Technology Stack : Mimesis library, Python
Code Type : Function
Code Difficulty : Intermediate
def generate_random_phone_number(country_code='US'):
from mimesis import Person, Address
phone_number = Person().phone()
if country_code == 'US':
return phone_number
else:
return f'+{country_code} {phone_number}'