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

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

I want to do something like this:

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

Help!

7条回答
  •  醉酒成梦
    2021-01-31 15:50

    If I remember my QBasic, right, left and mid do something like this:

    >>> s = '123456789'
    >>> s[-2:]
    '89'
    >>> s[:2]
    '12'
    >>> s[4:6]
    '56'
    

    http://www.angelfire.com/scifi/nightcode/prglang/qbasic/function/strings/left_right.html

提交回复
热议问题