Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Literals - the data in itself

Now that you have a little knowledge of some of the powerful features offered by the print() function, it's time to learn about some new issues, and one important new term - the literal. 

A literal is data whose values are determined by the literal itself. 

As this is a difficult concept to understand, a good example may be helpful. 

Take a look at the following set of digits: 

123

Can you guess what value it represents? Of course you can - it's one hundred twenty three

But what about this: 

c

Does it represent any value? Maybe. It can be the symbol of light, for example. It also can be the constant of integration. Or even the length of a hypotenuse in the sense of a Pythagorean theorem. There are many possibilities. 

You cannot choose the right one without some additional knowledge. 

And this is the clure: 123 is a literal, and c is not. 

You use literals to encode data and to put them into your code.  We're now going to show you some conventions you have to obery when using Python. 

Literals - the data in itself

Let's start with a simple experiment - take a look at the snippet in the editor. 

The first line looks familiar. The second seems to be erroneous due to the visible lack of quotes. 

If everything went okay, you should now see two identical lines. 

What happened?> What does it mean? 

Through this example, you encounter two different types of literals: 

  • string, which you already know. 
  • and an integer number, something completely new. 

The print() function presents them in exactly the same way - this example is obvious, as their human-readable representation is also the same.  Internally, in the computer's memory, these two values stored in completely different ways - the string exists as just a string - a series of letters. 

The numbers converted in machine representation (a set of bits). The print() function is able to show them both i a form readable to humans. 

We're now going to be spending some time discussing numeric literals and their internal life. 

 

Literals - the data in itself

David Khieu
Module by David Khieu, updated more than 1 year ago

Description

Literals - the data in itself Now that you have a little knowledge of some of the powerful features offered by the print() function, it's time to learn about some new issues, and one important new term - the literal.
No tags specified