📜  从电话号码中提取区号python代码示例

📅  最后修改于: 2022-03-11 14:45:24.160000             🧑  作者: Mango

代码示例1
#this only works for numbers in Toronto or the greater toronto area, but its simple to expand it for more areas.
phone = input("Enter a 10 digit phone number: ")
phone = str.replace(phone, "(", "") #removes brackets
phone = str.replace(phone, ")", "") #removes brackets
phone = str.replace(phone, "-", "") #removes dashes
phone = str.replace(phone, " ", "") #removes spaces
areacode = phone[0:3]
if areacode == "416" or areacode == "647":
    print("This is a Toronto number")
elif areacode == "905" or areacode == "289":
    print("This is a GTA number")