I am trying to make python take a string, separate the characters before another character eg: "10001001010Q1002000293Q100292Q". I want to separate the string before each Q and have python create either a list or another string. I cannot figure this out for the life of me.
2 Answers
You can do this using the split function, give "Q" as a parameter to the split function then you can slice the list to only get the numbers before Q.
num = "10001001010Q1002000293Q100292Q"
print(num.split("Q")[:-1])
Split() function: https://www.w3schools.com/python/ref_string_split.asp
Slicing: https://www.w3schools.com/python/python_strings_slicing.asp
"10001001010Q1002000293Q100292Q".split('Q')dir()on your string, e..gs='123Q456'; dir(s)will give you a list of methods that a string supports.splitandpartitionsound like something that divides strings.help(split)andhelp(partition)will give you a description of what they do. Try this out.