Can anyone help me with the source code in python which can be used to remove the characters which have odd index in a give string.
For example if the given string is 'python' then I am looking for the output 'pto'. My index is starting from 0.
You can use '%' to write related program. If mod of 2 is equal to 0 you can take that character and if it is not equal to 0, you can ignore that character.
final_str = ""
for i in range(len(str)):
if i % 2 == 0:
final_str = final_str + str[i]
The above code will print the output as: