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

String methods

时间:2014-07-07 15:42:12      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   2014   cti   for   

A method is similar to a function – it takes arguments and returns a value – but the syntax is different. For example, the method upper takes a string and return a new string with all uppercase letters. Instead of the function syntax upper(text), it uses the method syntax text.upper().

bubuko.com,布布扣                       

This form of dot notation specifies the name of the method, upper, and the name of the string to apply the method to, text. The parentheses indicate that this method has no parameters.

A method call is called an invocation; in this case, we would say that we are invoking upper on the word.

 bubuko.com,布布扣

As it turns out, there is a string method named find that is remarkably similar to the function we wrote. Actually, the find method is more general than our function: it can find substrings, not just characters:

 bubuko.com,布布扣

It can take as a second argument the index where it should, and the third argument the index where it should end:

bubuko.com,布布扣 

 

from Thinking in Python

 

String methods,布布扣,bubuko.com

String methods

标签:style   blog   http   2014   cti   for   

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

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