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

Python Python Basics Types and Branching Booleans

Ryan Butts
Ryan Butts
1,479 Points

What does craig mean when he says "string literals" or "boolean literals"? What does "literals" mean?

Just a bit confused by the term literals and how it relates to strings, booleans, and I guess the other data types as well? Thanks!

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Ryan Butts! A "literal" in computer science is a fixed value. For instance, the string "hello world" is a string literal. The "opposite" of a literal (if you want to think of it that way), is a variable.

Take this example:

my_string = "Hello World"
my_bool = True

print("Hi, Ryan")  # print a string literal
print(my_string)  # print a variable
print(my_bool)    # print a variable
print(False)          # print a boolean literal

The variable my_string holds a string literal of "Hello World". And the variable my_bool holds the boolean literal True. Because variables are just that, they don't really have a type until they are defined. Thus, if I were to say I'm printing a boolean literal, I would mean that I'm either printing True or False as opposed to a variable that holds that value.

Hope this helps! :sparkles:

boi
boi
14,242 Points

Nicely explained. 👍

Thank You for explaining, Jennifer!