Python literals

Module 2 · Python literals · Lesson 1 of 6

Literals

When you wrote "Hello" or 42 in your programs, you were using literals. A literal is simply a value written literally into your code — the data itself, spelled out, rather than calculated or stored under a name.

Four literals, four types
42inta whole number
3.14floathas a decimal point
"hi"strtext in quotes
Truebooltrue or false

Here's the key idea: Python looks at how you write a literal and decides what type of data it is. 42 is a whole number, so it's an integer. 3.14 has a decimal point, so it's a float. Quotes make it text; the words True and False make it a boolean.

Type matters because it decides what Python can do with a value — you can multiply numbers, but not the word “hello.” The rest of this section takes each of these four types in turn, starting with the most familiar: whole numbers.