首页 > 其他 > 详细

Find and counter

时间:2014-06-24 12:39:01      阅读:329      评论:0      收藏:0      [点我收藏+]

Find:

bubuko.com,布布扣                       

In a sense, find is the opposite of the [] operator. Instead of taking an index and extracting the corresponding character, it takes a character and finds the index where that character appears. If the character is not found, the function returns -1.

This pattern of computation – traversing a sequence and returning when we find what we are looking for – is called a search.

 

Looping and counting

The following program counts the number of times the letter a appears in a string:

 bubuko.com,布布扣

This program demonstrates another pattern of computation called a counter. The variable count is initialized to 0 and then incremented each time an a is found. When the loop exits, count contains the result – the total number of a’s.

 

from Thinking in Python

Find and counter,布布扣,bubuko.com

Find and counter

原文:http://www.cnblogs.com/ryansunyu/p/3805087.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!