码迷,mamicode.com
首页 > 其他好文 > 详细

Find and counter

时间:2014-06-24 12:38:45      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ext   com   2014   

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

标签:style   blog   http   ext   com   2014   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!