1. How do you reverse a string?
Example:
def reverse_string(s):
return s[::-1]
print(reverse_string("hello")) # Output: "olleh"
2. How do you determine if a string is a palindrome?
Example:
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome("radar")) # Output: True
3. How do you calculate the number of numerical digits in a string?
Example:
def count_digits(s):
return sum(1 for char in s if char.isdigit())
print(count_digits("abc123def456")) # Output: 6