python divide string in half 1

python divide string in half

firstpart, secondpart = string[:len(string)/2], string[len(string)/2:]

Here is what the above code is Doing:
1. We’re using the len() function to get the length of the string.
2. We’re using the / operator to divide the length by 2.
3. We’re using the : operator to slice the string.
4. We’re using the len() function again to get the length of the string.
5. We’re using the / operator to divide the length by 2.
6. We’re using the + operator to add the two parts together.

Similar Posts