What I want to do is:
mystr = i_return_a_string()
fst_part, snd_part = mystr[:4], mystr[4:]
But I'd be happier if this can be done (with a built-in function/method) like:
fst_part, snd_part = i_return_a_string().cut_at(4)
This is somewhat like str.partition, the difference is that I want to specify the index.
Is there a method for this?
if not, is what I have above the best way?
In this example, mystr is only needed as a temporal storage for the return value (of the function i_return_a_string), never to be referred again, which makes me a little uncomfortable.
strmethods? Try writing your own function then if you have problrms post another question.fst_part, snd_part = mystr[:4], mystr[4:]- is the idiomatic way to do this in Python. There's nocut_atstring method or function built in (but you could write one if you liked).mystryou could makei_return_a_string()return a tuple of strings - that is do the slicing already inside the function.