python 处理特殊的数字字符
2017-12-06 本文已影响0人
hapjin
处理特殊的数字
- 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 10.0 Character Code Charts
