Python: Remove First Three Lines From String - 'alok' to 'alok'
You can simply use string slicing to remove the first three characters and get the desired output 'alok'. Here's an example:
s = 'a\nb\nc\nalok'
s = s[4:] # remove first three characters
print(s) # output: 'alok'
Alternatively, you can split the string by newline characters, remove the first three elements, and then join the remaining elements back into a single string. Here's an example:
s = 'a\nb\nc\nalok'
s = '\n'.join(s.split('\n')[3:])
print(s) # output: 'alok'
原文地址: https://www.cveoy.top/t/topic/lOMU 著作权归作者所有。请勿转载和采集!