Slicing & Indexing Tasks

1.Write a function that takes a string and returns a new string consisting of its first and last character. 2.Write a function that reverses a given string. 3.Given a string, extract and return a substring from the 3rd to the 8th character (inclusive). 4.Write a function that returns every second character from a given string. 5.Write a function that replaces the middle third of a string with asterisks. If the length of the string is not divisible by 3, adjust the middle third accordingly. 6.Write a function that checks if a given string is a palindrome (reads the same backward as forward). 7.Given an email address, extract and return the domain. 8.Write a function that returns every third character from a given string. 9.Write a function that extracts and returns characters at even indices from a given string. 10.Write a function that skips every second character and then reverses the resulting string.

Apr 20, 2025 - 09:32
 0
Slicing & Indexing Tasks

1.Write a function that takes a string and returns a new string consisting of its first and last character.

Image description

2.Write a function that reverses a given string.

Image description

3.Given a string, extract and return a substring from the 3rd to the 8th character (inclusive).

Image description

4.Write a function that returns every second character from a given string.

Image description

5.Write a function that replaces the middle third of a string with asterisks. If the length of the string is not divisible by 3, adjust the middle third accordingly.

6.Write a function that checks if a given string is a palindrome (reads the same backward as forward).
7.Given an email address, extract and return the domain.
8.Write a function that returns every third character from a given string.
9.Write a function that extracts and returns characters at even indices from a given string.
10.Write a function that skips every second character and then reverses the resulting string.