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 trialKaci Jenkins
860 Pointshow do I set a variable to true?
help me.
admitted = None
if age >13:
print("admitted = 1")
1 Answer
Charlie Gallentine
12,092 PointsWhile 1 is a 'true' value in binary, in python, it is a number. In your case, ignoring the print() statement, admitted would equal the number 1. Because it is in a print statement, admitted would still equal its value at initialization: None, you are simply printing the string "admitted = 1" rather than reassigning its value.
I would go with something like this:
admitted = None
if age >13:
admitted = True
In python, to set a value to a boolean, you assign it the same way you would set a string or integer:
integer_variable = 4
string_variable = "Cheese"
boolean_variable = True
other_boolean_variable = False
Hope that helps!