Computer Science, asked by shilakumar9189, 1 year ago

Concatenated string with uncommon characters in Python?

Answers

Answered by Anonymous
0

Answer:

The problem of case changes a string is quite common and has been discussed many times. Sometimes, we might have a problem like this in which we need to convert the odd character of string to upper case and even positioned characters to lowercase. Let’s discuss certain ways in which this can be performed.

Method #1 : Using upper() + lower() + loop

This task can be performed in brute force method in a way that we iterate through the string and convert odd elements to uppercase and even to lower case using upper() and lower() respectively.

Explanation:

This task can be performed in brute force method in a way that we iterate through the string and convert odd elements to uppercase and even to lower case using upper() and lower() respectively.

# Python3 code to demonstrate working of

# Alternate cases in String

# Using upper() + lower() + loop

# initializing string

test_str = "geeksforgeeks"

# printing original string

print("The original string is : " + str(test_str))

# Using upper() + lower() + loop

# Alternate cases in String

res = ""

for idx in range(len(test_str)):

if not idx % 2 :

res = res + test_str[idx].upper()

else:

res = res + test_str[idx].lower()

# printing result

print("The alterate case string is : " + str(res))

Similar questions