Learning Resources

Language elements constants and numbers and strings

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

Numbers in Python are of three types - integers, floating point and complex numbers.

An examples of an integer is 2 which is just a whole number.
Examples of floating point numbers (or floats for short) are 3.23 and 52.3E-4. The E notation indicates powers of 10. In this case, 52.3E-4 means 52.3 * 10-4. Examples of complex numbers are (-5+4j) and (2.3 - 4.6j)

Note for Experienced Programmers - There is no separate 'long int' type. The default integer type can be a value of any length.

A string is a sequence of characters. Strings are basically just a bunch of words. The words can be in English or any other language that is supported in the Unicode standard, which means almost any language in the world.

Note for Experienced Programmers - There are no "ASCII-only" strings because Unicode is a superset of ASCII. If a strictly ASCII-encoded byte-stream is needed, then use str.encode("ascii"). By default, all strings are in Unicode.