Literals

We start by introducing literals. Literals are how we write values in a programming language. You need to know that there are different types of values and that each type has its own literals. We introduce the Python literals for the types corresponding to integer numbers (int), floating point numbers (float), text (string), truth values (boolean), tuples (pairs, triples, etc) and lists.

Literals for integer numbers

3
3
-1000
-1000
1234567890987654321234567890987654321
1234567890987654321234567890987654321
-1234567890987654321234567890987654321
-1234567890987654321234567890987654321
0
0

Literals for floating point numbers

Please notice the use of comments in the code to bring your attention to some details.

The # symbol introduces a one line comment.

3.141592653589793
3.141592653589793
1.4142135623730951
1.4142135623730951
-3.141592653589793
-3.141592653589793
# Notice: scientific notation. 

0.123456789e2
12.3456789

Boolean literals (there are only 2!)

True
True
False
False

String literals

Strings are used to deal with text in programs.

'Hello to you!'
'Hello to you!'
# Notice: by combining '' and "" you can include these in the text!

"Hello to 'you'!"
"Hello to 'you'!"
'Hello to "you"!'
'Hello to "you"!'
# Notice: you can include line breaks (you then need the three ''' ''')
'''hello
to 
you!
'''
'hello\nto \nyou!\n'

Tuples (pairs, triples, etc)

(1,2)
(1, 2)
(3.141592653589793, 'Pi!')
(3.141592653589793, 'Pi!')
(3.141592653589793, 'Pi!', True)
(3.141592653589793, 'Pi!', True)

Lists

[]
[]
[1,2,3,4]
[1, 2, 3, 4]