推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
ffxung
V2EX  ›  Python

为什么 unicode 的中文字符串,调用 isalpha()或 isalnum()返回的是 True 呢?

  •  
  •   ffxung · Oct 20, 2014 · 6880 views
    This topic created in 4400 days ago, the information mentioned may be changed or developed.
    例如:
    s = u"中国"
    print s.isalpha()
    输出竟然为True. 这是什么原因?
    那么想判断字符串是否只有字母组成出了正则,还有什么好方法?
    2 replies  •  2014-10-21 10:37:55 +08:00
    messense
    messense
    Oct 20, 2014
    1
    先转成 str 貌似可以...
    qdcanyun
    qdcanyun
    Oct 21, 2014
    2
    试试s.encode('utf-8').isalpha()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2285 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 11:42 · PVG 19:42 · LAX 03:42 · JFK 06:42
    ♥ Do have faith in what you're doing.