Python string find() examples

Results 1 to 3 of 3
  1. #1
    Apprentice betty12 is offline
    MemberRank
    Jun 2022 Join Date
    6Posts

    Python string find() examples

    I'm looking for examples, but I'm not finding any.
    Are there any examples on the internet? I'd like to know what it returns when it can't find something, as well as how to specify the starting and ending points, which I assume will be 0, -1.
    Code:
    >>> x = "Hello World"
    >>> x.find('World')
    6
    >>> x.find('Aloha');
    -1
    Could you please help me? But I'm not convinced.


  2. #2
    Iron like a Lion in Zion! vLife is offline
    Super ModRank
    Apr 2009 Join Date
    The BahamasLocation
    3,785Posts
    https://realpython.com/
    https://www.tutorialsteacher.com/python
    https://docs.python.org/3.8/library/...#library-index

    Are all great Python references that would help you with what you're looking for.

  3. #3
    Account Upgraded | Title Enabled! Fur Zi is offline
    MemberRank
    Feb 2012 Join Date
    HellLocation
    271Posts
    Q: I'd like to know what it returns when it can't find something
    A: You can see it in your output with -1 since Aloha is not present in the string at all.

    Q: how to specify the starting and ending points
    A: It will find the whole string you put inside find function in variable x.



Advertisement