我们可以使用Python内置的set数据类型来解决此问题。该数据类型可以用来去除序列中的重复元素,因为set只包含唯一的元素。因此,我们可以将输入的字符串转换为set,并将其与原始字符串进行比较。如果set中的元素数小于原始字符串中的元素数,则字符串中存在重复的字符。
下面是示例代码:
def has_duplicate_chars(input_str):
return len(set(input_str)) < len(input_str)
# 使用示例:
print(has_duplicate_chars("hello")) # True
print(has_duplicate_chars("world")) # False