Python Forum
Basic if/then help (I'm sorry)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic if/then help (I'm sorry)
#1
Basic question from a complete noob. I'm sorry.

Testing if statement and for loops. Populating a list, creating an empty list, finding some values and appending that new empty list. I then want to just print that list.

If I print within the 'if' statement it outputs but I don't want to see the entire iteration.

I can also print the list after the program has completed.

But, I'd like the if statement to finish and then as the next command print the list.

Missing something simple / dumb here. Sorry. Suggestions / corrections?


>>> fruits=['apples', 'bananas', 'oranges']
>>> vowel_names=[]
>>> print(vowel_names)
[]
>>> for i in fruits:
...     if i[0] in "aeiou":
...         vowel_names.append(i)
... print(vowel_names)
  File "<stdin>", line 4
    print(vowel_names)
        ^
SyntaxError: invalid syntax
Reply


Messages In This Thread
Basic if/then help (I'm sorry) - by racichb - Aug-29-2019, 07:21 PM
RE: Basic if/then help (I'm sorry) - by Yoriz - Aug-29-2019, 07:45 PM
RE: Basic if/then help (I'm sorry) - by racichb - Aug-29-2019, 08:30 PM
RE: Basic if/then help (I'm sorry) - by ThomasL - Aug-30-2019, 08:02 AM
RE: Basic if/then help (I'm sorry) - by perfringo - Aug-30-2019, 08:33 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020