如果水果在您的文本文件中位于不同的行中,请尝试这种方式fruits = open('fruits.txt','r') #opening the filelines = fruits.readlines() #making list, with the line breakfruit = [] #empty list to later append without the line breakfor line in lines: #looping through the list stripped = line.strip('\n') #removing the linebreak fruit.append(stripped) #appending to the new listmain_tup = tuple(fruit) #making it to a tuple print(main_tup)这是使用列表理解编写此代码的更短方法。fruits = open('some.txt','r')lines = fruits.readlines()fruit = [line.strip('\n') for line in lines] #list comprehensionmain_tup = tuple(fruit)print(main_tup)