简体   繁体   中英

How to search substring in python?

I want to search through a text file and output substrings that match the user input, but when my program searches each line I want it to only search the characters between the "|"character and the end of the line. But I keep getting the following error:

You should use slices. Just replace , with : in your code:

y = line[char_pos:x]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM