Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Входен низ и търсена дума
- my_string = "Hello GoSho, welcome to the Gosho world. This GOSHO is amazing."
- search_word = "gosho"
- # Преобразуване на низа и думата в малки букви
- my_string_lower = my_string.lower()
- search_word_lower = search_word.lower()
- # Проверка дали думата присъства в низа
- if search_word_lower in my_string_lower:
- print(f"The word '{search_word}' is present in the string.")
- else:
- print(f"The word '{search_word}' is not present in the string.")
- # Броене на срещанията на думата в низа
- count = my_string_lower.count(search_word_lower)
- print(f"The word '{search_word}' appears {count} times in the string.")
- # Намиране на всички позиции на срещанията на думата в низа
- positions = []
- index = 0
- while index < len(my_string_lower):
- index = my_string_lower.find(search_word_lower, index)
- if index == -1:
- break
- positions.append(index)
- index += len(search_word_lower)
- print(f"The word '{search_word}' appears at positions: {positions}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement