Source code for string_operators
"""
This module contains basic string operations.
"""
[docs]
def concatenate(str1, str2):
"""
Concatenates two strings.
Parameters:
str1 (str): The first string.
str2 (str): The second string.
Returns:
str: The concatenation of the two strings.
"""
return str1 + str2
[docs]
def reverse_string(string):
"""
Reverses a given string.
Parameters:
string (str): The string to reverse.
Returns:
str: The reversed string.
"""
return string[::-1]
[docs]
def count_vowels(string):
"""
Counts the number of vowels in a string.
Parameters:
string (str): The string to check.
Returns:
int: The number of vowels in the string.
"""
vowels = "aeiouAEIOU"
return sum(1 for char in string if char in vowels)
[docs]
def to_uppercase(string):
"""
Converts the string to uppercase.
Parameters:
string (str): The string to convert.
Returns:
str: The string in uppercase.
"""
return string.upper()