Run
# Input string x = "Hello, World!" # Specific characters ch1 = "e" ch2 = "r" # Find indices of specific characters index_1 = x.find(ch1) if index_1 != -1: index_2 = x.find(ch2, index_1) if index_1 != -1 and index_2 != -1: # Get the substring between specific characters substring = x[index_1 + 1 :index_2] else: print("Error: One or both of the characters not present") # Print the result print(substring)
Output