word = "milk,bread,butter" food = word.split(",") for i in food: i = i.capitalize() print(food)
По интуиции нашел два способа вывода нужного результата, но не могу понять, почему первый не работает.
Первый:
mas = [] word = "milk,bread,butter" food = word.split(",") for i in food: i = i.capitalize() mas.append(i) print(mas)
word = "milk,bread,butter" food = word.split(",") for i in range(len(food)): food[i] = food[i].capitalize() print(food)