A Byte of Python

Chapter 4. The Basics of Python

Table of Contents

Literal Constants
Numbers
Booleans
Strings
Variables
Identifier Naming
Data Types
Objects
Using Variables
Output
How It Works
Logical and Physical Lines
Indentation
The Hangman Gaming Room
Output
How It Works
Summary

Just printing 'Hello World' isn't enough, is it? You want to do more than that - you want to take in some input from the user, do something with it and return some information, which is basically what most programs do. We can achieve this using constants and variables.

Literal Constants

An example of a literal constant is a number like 5, 1.23, 2.95e-3 or a string like 'This is a string' or "It's a string!". It is called a literal because you use its value literally, for example, the number 2 always represents itself and nothing else. It is a constant because its value cannot be changed. Hence, they are referred to as literal constants.

We will encounter two types of literal constants - numbers and strings.