WAP to display alternate characters of a string
Answers
Answered by
1
Answer:
Hey! This works only in python...
str = input('Enter some thing: ')
for i in range(len(str)):
print(str[i+2], end='')
HOPE THIS HELPS!!
Answered by
3
string = input("Enter a string: ")
print("It's alternate characters are: ", string[::2])
The above program is done using string slicing, which the act of extracting a substring from a given string.
A slice function follows a similar syntax:
string_name[start:stop:step]
- start - indicates from which index value it must traverse.
- stop - indicates till which index value it must stop traversing.
- step - indicates by how many characters it must skip when traversing.
We've given the step value here as 2. This means, it will display the characters after every 2 characters, which is displaying the alternate characters.
Similar questions
Accountancy,
3 months ago
Computer Science,
3 months ago
History,
3 months ago
Math,
7 months ago
Math,
7 months ago
English,
11 months ago