Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJake Nisenboim
3,374 PointsUnderstanding Greater than symbol Python "> "
My code is as follows:
shopping_list = list()
print("What should we pick up at the store?")
print("Enter 'DONE' to stop adding items.")
while True:
new_item = input("> ")
if new_item == 'DONE':
break
shopping_list.append(new_item)
print("Added! List has {} items.".format(len(shopping_list)))
continue
print("Here's your list:")
for item in shopping_list:
print(item)
I don't understand what the
while True:
new_item = input("> ")
means?
while the input of new_item is (What?)
Can someone help me understand what this means ("> ") and why it is being used?
I assume it must mean anything? Because it would be = anything - 'DONE' can be an input for new_item.
Thanks.
1 Answer
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Jake
The input method take an argument which is displayed just before the user input. So "> " just resembels a symbol to prompt the user that he need to enter somthing. you then store the user input in a variable called new_item.
# you could have also written it like so
new_item = input("Ok so what do you want to pick up ? " )
Jake Nisenboim
3,374 PointsJake Nisenboim
3,374 PointsOhh wow makes sense thank you !
Jake Nisenboim
3,374 PointsJake Nisenboim
3,374 PointsOne other question -- what does list() represent / mean ?
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsAndreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Jake
a list in python is similar to an array in other languages. you can declare a variable as list like above shopping_list = list() or you could use the shorthand notation of a list which is [], so you could also have declared shopping_list = [] which would be the same thing.
hope that makes sence.
Jake Nisenboim
3,374 PointsJake Nisenboim
3,374 PointsSorry, I understand what a list is however, not what list() (the open and closing brackets with nothing in it), nor what [] would mean otherwise.
Thanks.
Jake Nisenboim
3,374 PointsJake Nisenboim
3,374 PointsWait, it just means we are starting an empty list...?
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsAndreas cormack
Python Web Development Techdegree Graduate 33,011 Pointsthe opening and closing parenthesis means you are creating an object of the built in list class i.e your creating an empty list
so if i have a class called Cat for example and i wanted to create an object of this cat class i would do it like so