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 Introducing Lists Meet Lists Creation

kelsang sherab
kelsang sherab
749 Points

What is the meaning and purpose of 'literals' ??

I am trying to understand the meaning of the word literal as in string literal list literal numeric literal etc

So i have read various explanations online but I don't get it. I do not understand what does "notations for constant values of some built-in types" actually mean? What would a programing world look like if we did not have the concept of literals?

1 Answer

Cooper Runstein
Cooper Runstein
11,850 Points

Literals are best discussed in comparison to variables:

my_variable = 1 # this is a variable
1 # this is a literal

A variable can store data, and that data can change, while a literal is constant, like 1 or 'hello', you can't change these because they would no longer be themselves. Imagine if everything were explicit variables:

#Normal
my_list = [1,2,3]
one = 1
for x in my_list:
  return x += one

By not having to save 1 as a variable one, we can save a line of code. In this small example, that's not a big deal, but if we can save one extra line for every five lines of code we write, that adds up quickly.

kelsang sherab
kelsang sherab
749 Points

Thanks Cooper!! Great answer.