单选题 适中
#15600

在Python中,运行下面代码的输出结果是?( ) text = "apple banana apple cherry banana" words = set(…

在Python中,运行下面代码的输出结果是?( )

text = "apple banana apple cherry banana"
words = set(text.split())
print(len(words))
未登录也能判分,登录后才会记录
答案与解析
正确答案:B
解析

text.split()将字符串按空格分割成单词列表,结果为["apple", "banana", "apple", "cherry", "banana"]。使用set()函数将其转换为集合时,重复的单词会被去除,最终集合为{"apple", "banana", "cherry"},因此长度为3。