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 trial
Konrad Gołda
735 PointsConsole error possible?
Hi,
is there a console error possible, or my computer is just not good enough or something?
#in REPL, instead of ", yum" I have typed:
dessert += ", YUMMY IN MY TUMMY"
#but the result was like this:
>>> dessert
'chocolate and marshmallows an
MMY'
#later on, when I typed command:
>>> dessert
# for the second time, my console displayed this:
>>> dessert = dessert + " and
>>> dessert
'chocolate and marshmallows an
>>> dessert += ", YUMMY IN MY
>>> dessert
'chocolate and marshmallows an
MMY'
>>> dessert
'chocolate and marshmallows an
MY'
>>>
KeyboardInterrupt
>>>
KeyboardInterrupt
>>>
#so it cutted a lot of a string. Can someone explain why this occurred and how to deal with this?
#THANKS! ;)
1 Answer
Jeff Muday
Treehouse Moderator 28,732 PointsOrder is important when you run Python (and the REPL). Note that dessert must be defined before you can use the "+=" operator.
If dessert is not defined it will throw an error like shown below.
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> dessert += ", yum"
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
dessert += ", yum"
NameError: name 'dessert' is not defined
If dessert were defined before you use the "+=" operator, like below, it would work.
>>> dessert = 'chocolate and marshmallows'
>>> dessert += ", yum"
>>> print(dessert)
chocolate and marshmallows, yum