用Python格式化电话号码的最佳方式是什么?

编程入门 行业动态 更新时间:2024-10-27 20:25:52
本文介绍了用Python格式化电话号码的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我所拥有的是一个10位或更多位的字符串,我怎样才能把它作为一个电话号码来格式化?

一些简单的例子:

555-5555 555-555-5555 1-800-555-5555

我知道这些并不是格式化的唯一方法,如果我自己做,很可能会遗漏。有没有一个Python库或格式化电话号码的标准方式?

解决方案

for library:phonenumbers( pypi , )

$ b

谷歌公共库的Python版本用于解析,格式化,存储和验证国际电话号码。

自述文件不足,但是我发现代码已经很好的记录了。

If all I have is a string of 10 or more digits, how can I format this as a phone number?

Some trivial examples:

555-5555 555-555-5555 1-800-555-5555

I know those aren't the only ways to format them, and it's very likely I'll leave things out if I do it myself. Is there a python library or a standard way of formatting phone numbers?

解决方案

for library: phonenumbers (pypi, source)

Python version of Google's common library for parsing, formatting, storing and validating international phone numbers.

The readme is insufficient, but I found the code is well documented.

更多推荐

用Python格式化电话号码的最佳方式是什么?

本文发布于:2023-10-12 02:38:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电话号码   方式   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!