1

I have this string my_string = '717460881855742062' how can I split it in half? The string is auto-generated so just splitting by the 1 won't work

1
  • do you know about slicing and len(...)? Commented Jun 2, 2020 at 19:41

2 Answers 2

3

You can try do this way:

firsthalf, secondhalf = my_string[:len(my_string)//2], my_string[len(my_string)//2:]
Sign up to request clarification or add additional context in comments.

Comments

1

Something like this should do the job:

my_string = '717460881855742062'

length = int(len(my_string) / 2)
first_part = my_string[:length]
second_part = my_string[length:]

print(first_part)
print(second_part)

output:

717460881

855742062

You can modify it and make sure you take also handle the situation where the length%2 is not 0.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.