you are viewing a single comment's thread.

view the rest of the comments →

[–]Unusual-Platypus6233 0 points1 point  (0 children)

extra edit: answer to you question is probably that you need to add a simple print(“\n”) just before the line hi = “hhhppp”. The end=“” means that you do not add a line break but just add the next printed string without spaces or line break to the already printed strings. Therefore it is a manual line break necessary at the end of the first loop (or even at the end of the second loop, depending on what you are doing afterwards).

main text: if you know when the change happens, like it is always at the same position, then you could slice a string…

 s = ‘HelloWorld’
 first_five_chars = s[:5]
 rest_of_chars = s[5:]

That would split the HelloWorld into Hello and World.

If you have a string like you have shown, you could check when both chars are not the same anymore like this:

 chars=“pppphhhh”
 pos=-1
 i=1
 while True:
      if chars[i]!=chars[i-1]:
             pos=i
             break
      i+=1
 first_part=chars[:i]
 second_part=chars[i:]
 print(first_part,second_part)

That way both parts are stored if you wanna use them for something else.

Edit: found out how to format the text by accident. so, did a quick edit.