首页 > 其他 > 详细

String methods

时间:2014-07-07 15:41:14      阅读:315      评论:0      收藏:0      [点我收藏+]

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

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

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