• String methods


    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().

                           

    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.

     

    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:

     

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

     

     

    from Thinking in Python

     

  • 相关阅读:
    第七次作业-话费充值
    第七次作业-qq登录&跳转
    第六次作业
    第五次作业
    第四次作业
    jsp第二次作业
    第一次jsp作业
    第九次作业
    第八次作业
    第七次2作业
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/3815171.html
Copyright © 2020-2023  润新知