Python capitalization, string division

Asked 2 years ago, Updated 2 years ago, 137 views

a = When there is a string called "Aaron MOOYAustralia Midfielder" You are about to add a "spacing or -" separated by a name country position. To do that, you want to find the part that is separated by lowercase-> uppercase letters. I ask for your help me.

python string uppercase

2022-09-22 15:32

1 Answers

For the most basic (?) we need to use the for statement, islower(), isupper() function. The islower function determines which str is composed of lowercase letters The isupper function determines which str is composed of uppercase letters.

The approximate code is as follows:

mystring = 'AaronMOOYAustraliaMidfielder'
answer = mystring[0]
for idx, char in enumerate(mystring[1:]):
    if mystring[idx].islower() and char.isupper():
        answer += '-'
    answer += char
print(answer)


2022-09-22 15:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.