2

I'm new to programming, and I'm trying to understand the basics of python. I was trying to figure out how "range" works in lists, so I wrote this code:

words = ["apple", "pinapple", "orange", "stop", "blueberry", "banana"]

for g in range(len(words)) :
    if words[g] == "stop":
        break 
    print (words[g]) 

But I wondered how I could write down the words "apple", "pinapple", and "orange", as a separate list?

I tried to set a new variable "test" and add values to it:

words = ["apple", "pinapple", "orange", "stop", "blueberry", "banana"]
test = []
for g in range(len(words)) :
    if words[g] == "stop":
        break 
    test += words[g]
print (test)

but for some reason, the words suddenly split into separate letters:

['a', 'p', 'p', 'l', 'e', 'p', 'i', 'n', 'a', 'p', 'p', 'l', 'e', 'o', 'r', 'a', 'n', 'g', 'e']

I tried several other ways to change the result, but nothing worked.

P.S. I apologize if I wrote the question out of form, this is my first time asking questions here.

0 Answers0