Python: Is there an equivalent of mid, right, and left from BASIC?

后端 未结 7 1345
再見小時候
再見小時候 2021-01-31 15:11

I want to do something like this:

    >>> mystring = \"foo\"
    >>> print(mid(mystring))

Help!

7条回答
  •  太阳男子
    2021-01-31 15:35

    There are built-in functions in Python for "right" and "left", if you are looking for a boolean result.

    str = "this_is_a_test"
    left = str.startswith("this")
    print(left)
    > True
    
    right = str.endswith("test")
    print(right)
    > True
    

提交回复
热议问题