How do I get a substring of a string in Python?

前端 未结 13 1905
我寻月下人不归
我寻月下人不归 2020-11-22 00:32

Is there a way to substring a string in Python, to get a new string from the third character to the end of the string?

Maybe like myString[2:end]?

13条回答
  •  灰色年华
    2020-11-22 01:00

    If myString contains an account number that begins at offset 6 and has length 9, then you can extract the account number this way: acct = myString[6:][:9].

    If the OP accepts that, they might want to try, in an experimental fashion,

    myString[2:][:999999]
    

    It works - no error is raised, and no default 'string padding' occurs.

提交回复
热议问题