Is there a way to split a string into 2 equal halves without using a loop in Python?
Use the maxsplit parameter: a, b = s. split(maxsplit=1) .
Python String | split() separator : This is a delimiter. The string splits at this specified separator. If is not provided then any white space is a separator. maxsplit : It is a number, which tells us to split the string into maximum of provided number of times.
firstpart, secondpart = string[:len(string)/2], string[len(string)/2:]
a,b = given_str[:len(given_str)/2], given_str[len(given_str)/2:]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With