python – 如果字符串显然是title-case,为什么istitle()字符串方
发布时间:2020-12-20 12:39:37 所属栏目:Python 来源:网络整理
导读:在istitle()字符串方法中,Python 2.6.5手册中包含: Return true if the string is a titlecased string and there is at least one character,for example uppercase characters may only follow uncased characters and lowercase characters only cased o
在istitle()字符串方法中,Python 2.6.5手册中包含:
但在这种情况下,它返回false: >>> book = 'what every programmer must know' >>> book.title() 'What Every Programmer Must Know' >>> book.istitle() False 我错过了什么? 解决方法
方法title()不会改变字符串(字符串在Python中是不可变的).它会创建一个必须分配给变量的新字符串:
>>> book = 'what every programmer must know' >>> book = book.title() >>> book.istitle() True (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |