What is Literal – Python

In this article, we are going to learn about Literal in Python.

Literal in Python
Literal – Python

Definition: Literals are numbers or strings or characters that appear directly in a program. A list of some literals in Python is as follows:


21Integer Literal
79.83Floating Point Literal
‘P’Character Literal
“Hello Python”String Literal

Python also contains other literals, such as lists, tuple and dictionary. Details of all such literals are given in the forthcoming chapters.

Example Program on Literal

Let us consider a simple example that Print the message “I love CodeWin” as a string literal in Python.


>>> 'I love CodeWin'
'I love CodeWin'

As shown above, type I love CodeWin in IDE and hit enter. After hitting enter you’ll see the required message.

Value and Type on Literal

Programming Languages store data in form of input and output, and any type of data is represented in terms of values. Here value can be of any form like numbers, characters, and strings.

You may have noticed that in the above example we got ‘I love CodeWin’ as output in single quotes. However, we don’t know the type of value in it. To know the exact type of value, Python offers an in-built method called type.

Syntax to know the type of any value is type(value) :


>>> type('I love CodeWin)
<class 'str'>
>>> type(123)
<class 'int'>

Thus, when the above examples are executed in Python IDE, the return type of value is passed to the in-built function type().

Similar Posts