Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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:

Nicely explained. 👍

Ryan Caalim
Ryan Caalim
248 Points

Thank You for explaining, Jennifer!