Removing first x characters from string?

前端 未结 5 709
轻奢々
轻奢々 2020-12-23 02:36

How might one remove the first x characters from a string? For example, if one had a string lipsum, how would they remove the first 3 characters and get a resul

5条回答
  •  失恋的感觉
    2020-12-23 03:04

    Another way (depending on your actual needs): If you want to pop the first n characters and save both the popped characters and the modified string:

    s = 'lipsum'
    n = 3
    a, s = s[:n], s[n:]
    print(a)
    # lip
    print(s)
    # sum
    

提交回复
热议问题