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
Christopher Mamaloukas
1,383 PointsHow to change a variable's value in Python?
Hello!
I have a question about variables in Python. If we have an 'if statement' of the type:
"if 13 == 13"
and a variable:
"equals = 0"
What are we going to enter inside the if statement so the final result is
"equals = 1"
I would be thankful if you answer!
1 Answer
tobiaskrause
9,160 Pointsthe result of your if statement is fixed (ok we can have different results of course with else or some other statements inside the if statement etc. ... but the final result is still fixed and can just be changed after the finished if-statement.) cause it is an assignment. If you want to change the value of equals just write "equals = 2" after the if statement. You can also change values with your if-statement of course:
a = 1
b= True
while(b):
if a < 10:
a+= 1
else:
b = False
You just have to run the if-statements a couple of times and incerement the value ... and make sure the loop ends