In this python program, we will learn how to remove the character from an Odd index position in a string.
Here is the source code of the program to remove the character from an Odd index position in a string.
Python program to Remove Characters from an Odd Index Positions in a String Using For Loop
# Python program to Remove Characters from an Odd Index Positions in a String Using For Loop
# Take the Input From the User
str1 = input("Enter the String: ")
str2 = ''
for i in range(1, len(str1) + 1):
if(i % 2 == 0):
str2 = str2 + str1[i - 1]
print("\nOriginal String before Removing Characters from Odd Positions: ", str1)
print("Final String After Removing Characters from Odd Positions: ", str2)
Enter the String: Tutorialsrack is a online learning website
Original String before Removing Characters from Odd Positions: Tutorialsrack is a online learning website
Final String After Removing Characters from Odd Positions: uoilrc saoln erigwbie
Python program to Remove Characters from an Odd Index Positions in a String Using While Loop
# Python program to Remove Characters from an Odd Index Positions in a String Using While Loop
# Take the Input From the User
str1 = input("Enter the String: ")
str2 = ''
i = 1
while(i <= len(str1)):
if(i % 2 == 0):
str2 = str2 + str1[i - 1]
i = i + 1
print("\nOriginal String before Removing Characters from Odd Positions: ", str1)
print("Final String After Removing Characters from Odd Positions: ", str2)
Enter the String: Tutorialsrack is a online learning website
Original String before Removing Characters from Odd Positions: Tutorialsrack is a online learning website
Final String After Removing Characters from Odd Positions: uoilrc saoln erigwbie
Comments