美文网首页
python 处理特殊的数字字符

python 处理特殊的数字字符

作者: hapjin | 来源:发表于2017-12-06 21:36 被阅读0次

处理特殊的数字

  • int("771175596 ")
    Out[44]: 771175596
  • '⑦'.isdigit()
    Out[48]: True
  • "⑦⑦".isdigit()
    Out[51]: True

输出emoji字符

  • print('\U0001f604')
    😄
  • print('\U0001f44d')
    👍

判断某字符串中是否包含数字(包括特殊数字)

def hasNumbers(chat):
    return any(char.isdigit() for char in chat)
  • hasNumbers("ld ⑦")
    Out[76]: True
  • hasNumbers("59 world")
    Out[74]: True
  • hasNumbers("test")
    Out[75]: False

汉字转换成拼音

使用pypinyin包

  • 示例1
from pypinyin import pinyin
chat1 = "承认"
chatList = pinyin(chat1)
chatList
Out[56]: [['chéng'], ['rèn']]
words1 = [wordlist[0] for wordlist in chatList]
words1
Out[58]: ['chéng', 'rèn']
  • 示例2
chat2 = "城认"
chatList2 = pinyin(chat2)
words2 = [wordlist[0] for wordlist in chatList2]
words2
Out[62]: ['chéng', 'rèn']
  • 示例3
chat3 = "城朲"
chatList3 = pinyin(chat3)
chatList3
Out[65]: [['chéng'], ['rén']]
words3 = [wordlist[0] for wordlist in chatList3]
words3
Out[67]: ['chéng', 'rén']

特殊字符查询网站

Unicode Circled Numbers ① ② ③

1.png

Unicode 10.0 Character Code Charts

2.png

相关文章

  • python 处理特殊的数字字符

    处理特殊的数字 int("771175596 ")Out[44]: 771175596 '⑦'.isdigit()...

  • 字符编码与python字符串

    python字符串与字符编码 字符编码 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理。...

  • python2的编码和解码问题

    怀念python3 python3默认情况下,是通过Unicode直接编码操作的,对于字符串,特殊字符,数字的支持...

  • PythonQuickView by L0st

    PythonQuickView 处理字符串 列表 数字相关 元组 Python中的逻辑运算 Python中的If结...

  • Python2编码的问题

    1.怀念python3 python3默认情况下,是通过unicode直接编码操作的,对于字符串、特殊字符、数字的...

  • 数据类型和变量

    数据类型 Python可处理的数据类型包括:数字;字符串;布尔值;列表;字典;元组Python中有序字符的集合,被...

  • python对中文,英文.....字节判断

    python中判断字符是否是汉字、字母以及数字 在python处理数据的过程中,有时候需要判断给定的字符是否是汉字...

  • 2020-04-26

    Python 入门 学习使用 Python 处理数字与字符串,编写函数和条件语句;操作列表、集合、字典等常见数据类...

  • 字符编码的问题真是令人头疼!

    字符编码 字符串是一种数据类型,但是,字符串比较特殊的是还有一个编码问题。 因为计算机只能处理数字,如果要处理文本...

  • Unix & Linux 大学教程 第13、14章shell

    13.1 元字符 字母数字字符:字母和数字元字符:特殊字符 $TERM中的$ ...

网友评论

      本文标题:python 处理特殊的数字字符

      本文链接:https://www.haomeiwen.com/subject/duzlixtx.html