2008年01月16日 星期三 21:39
str='aaabbbccceddddd' Èç¹ûÎÒÒªËÑË÷×Ö·û´®ÖÐµÄ e£¬ ÇëÎÊÔõô±í´ï£¿ лл -- deSign thE fuTure -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080116/65c69feb/attachment.htm
2008年01月16日 星期三 21:50
str.find('e')
ÔÚ08-1-16£¬Ð¡Áú <freefis在gmail.com> дµÀ£º
>
> str='aaabbbccceddddd'
>
> Èç¹ûÎÒÒªËÑË÷×Ö·û´®ÖÐµÄ e£¬ ÇëÎÊÔõô±í´ï£¿ лл
>
> --
> deSign thE fuTure
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080116/717a7ccb/attachment.html
2008年01月16日 星期三 22:10
str='aaabbbccceddddd'
if 'e' in str:
print "yes"
ÔÚ08-1-16£¬Ð¡Áú <freefis在gmail.com> дµÀ£º
>
> str='aaabbbccceddddd'
>
> Èç¹ûÎÒÒªËÑË÷×Ö·û´®ÖÐµÄ e£¬ ÇëÎÊÔõô±í´ï£¿ лл
>
> --
> deSign thE fuTure
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080116/b03636e0/attachment.htm
2008年01月17日 星期四 00:49
лл¡«¡« ÔÀ´ÄÇô¼òµ¥¡«¡« ÄÇreÀïµÄ searchÊÇʲô×÷Óã¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080117/2fd59ff1/attachment.html
2008年01月17日 星期四 08:39
2008/1/17 小龙 <freefis在gmail.com>: > 谢谢~~ 原来那么简单~~ 那re里的 search是什么作用? > search可以在字符串的中间找到一个匹配的结果,而match是从字符串开始进行的。起点不同。 -- I like python! UliPad <>: http://code.google.com/p/ulipad/ meide < >: http://code.google.com/p/meide/ My Blog: http://www.donews.net/limodou
2008年01月17日 星期四 10:17
The re <file:///D:/Users/cn1ll290/Desktop/python/lib/module-re.html> module provides regular expression tools for advanced string processing. For complex matching and manipulation, regular expressions offer succinct, optimized solutions: re <file:///D:/Users/cn1ll290/Desktop/python/lib/module-re.html>Ä£¿éΪ¸ß¼¶×Ö·û´®´¦ÀíÌṩÁËÕýÔò±í´ïʽ¹¤¾ß¡£¶ÔÓÚ¸´Ôӵį¥ÅäºÍ´¦Àí£¬ÕýÔò±í´ïʽÌṩÁ˼ò½à¡¢ÓÅ»¯µÄ½â¾ö·½°¸¡£ >>> import re >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') ['foot', 'fell', 'fastest'] >>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat') 'cat in the hat' When only simple capabilities are needed, string methods are preferred because they are easier to read and debug: Èç¹ûÖ»ÐèÒª¼òµ¥µÄ¹¦ÄÜ£¬Ó¦¸ÃÊ×ÏÈ¿¼ÂÇ×Ö·û´®·½·¨£¬ÒòΪËüÃǷdz£¼òµ¥£¬Ò×ÓÚÔĶÁºÍµ÷ÊÔ¡£ >>> 'tea for too'.replace('too', 'two') 'tea for two' ÔÚ08-1-17£¬Ð¡Áú <freefis在gmail.com> дµÀ£º > > лл¡«¡« ÔÀ´ÄÇô¼òµ¥¡«¡« ÄÇreÀïµÄ searchÊÇʲô×÷Óã¿ > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080117/ab70a9ea/attachment.htm
2008年01月17日 星期四 10:29
给你贴个逻辑匹配字符串好了
def match(text, andwords=[], orwords=[], notwords=[]):
'''匹配字符串
'''
for notword in notwords:
if notword in text:
return False
for andword in andwords:
if andword not in text:
return False
for orword in orwords:
if orword in text:
return True
return True
>>> match('早上好啊,这里是火星', ['早上','火星'])
True
>>> match('早上好啊,这里是火星', ['早上','火星'], ['好啊','不好'])
True
>>> match('早上好啊,这里是火星', ['早上', '火星'], ['好啊', '不好'], ['很好'])
True
>>> match('早上好啊,这里是火星', ['早上', '火星'], ['好啊', '不好'], ['好啊'])
False
>>>
2008年01月17日 星期四 22:18
Äܸø¸ösearchµÄÀý×Óô~ лл -- deSign thE fuTure -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080117/62fca841/attachment.htm
2008年01月17日 星期四 22:22
2008/1/17 小龙 <freefis在gmail.com>: > 能给个search的例子么~ 谢谢 建议看文档。 -- I like python! UliPad <>: http://code.google.com/p/ulipad/ meide < >: http://code.google.com/p/meide/ My Blog: http://www.donews.net/limodou
Zeuux © 2025
京ICP备05028076号