2012年8月12日

python中str()和repr()区别

摘要: str函数,它会把值转换为合理形式的字符串,以便用户可以理解。repr函数,会创建一个字符串,它以合法的Python表达式的形式来表示值。例如:Java代码>>>printrepr("hello,world!")'hello,world!'>>>printrepr(1000L)1000L>>>printstr("hello,wolrd!")hello,wolrd!>>>printstr(1000L)1000repr(x)的功能也可以用`x`实现(注意, `是反引号,而 阅读全文

posted @ 2012-08-12 16:05 linzuxin 阅读(274) 评论(0) 推荐(0) 编辑

Python内置的字符串处理函数整理

摘要: 字符串长度获取:len(str)例:print '%s length=%d' % (str,len(str))字母处理全部大写:str.upper()全部小写:str.lower()大小写互换:str.swapcase()首字母大写,其余小写:str.capitalize()首字母大写:str.title()print '%s lower=%s' % (str,str.lower())print '%s upper=%s' % (str,str.upper())print '%s swapcase=%s' % (str,str.s 阅读全文

posted @ 2012-08-12 15:57 linzuxin 阅读(355) 评论(0) 推荐(0) 编辑

导航