Understanding Literals in Python
When starting with Python programming, it is important to get the basics right before we get into coding. In your very first class of Python, you will be introduced to phrases like keywords, variables, operators, literals, etc.
In this article, we are going to focus on the concepts for the definition and usage of literals. We will also be deep-diving into the types of literals in Python. So, without further ado, let’s get started!
Explore free Python courses
Explore How to Find an Armstrong Number Using Python
We will be covering the following sections today:
Check out: Top Python Online Courses and Certifications
What are Python Literals?
Python literals constant or fixed values in the source code that do not change during the execution of a program. We can also define Literals as the raw values that are given to Python variables.
Let’s consider the below examples for better understanding:
Literals are a way of representing data types in Python. They can be anything from numbers to textual data, Boolean values, etc. Let’s discuss the various types of literals –
Check out- Advantages of Python
Types of Python Literals
The usage of Python literals varies according to the type. Let’s look at the five types of literals Python has to offer:
Now, let’s talk about each of them in detail:
Check out- How to install Python
Numeric Literals
These literals contain only immutable numeric values. By immutable, it implies that one cannot changes its values during runtime.
From Python 3 onwards, numeric literals have three subtypes:
- Integers
- Float
- Complex
Let’s look at each of them in detail –
Integers
All the natural numbers – negative, zero, or positive are integers. We can also categorize them into the following types:
- Decimal integers – contain digits from 0 to 9. The base for decimal values is 10.
- Binary integers – contain only two digits- 0 and 1. The base for binary values is 2 and prefixed with “0b”.
- Octal integers – contain the digits from 0 to 7. The base for octal values is 8. In Python, the octal values are prefixed with “0o”.
- Hexadecimal integers – Contain digits from 0 to 9 and alphabets from A to F.
Consider the below Python examples of integer literals:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Integer literals\n \n \n \n \n \n \n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Positive\n \n \n x \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: #ff4500">\n 734 \n \n \n <span style="color: #808080;font-style: italic">\n #Negative \n y \n <span style="color: #66cc66">\n = - \n <span style="color: #ff4500">\n 8672 \n \n \n <span style="color: #808080;font-style: italic">\n #Binary \n a \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 0b111001100 \n \n \n <span style="color: #808080;font-style: italic">\n #Decimal \n b \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 21 \n \n \n <span style="color: #808080;font-style: italic">\n #Octal \n c \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 0o544 \n \n \n <span style="color: #808080;font-style: italic">\n #Hexadecimal \n d \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 0xC9 \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n ,y \n <span style="color: black">\n ) \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (a \n <span style="color: #66cc66">\n , b \n <span style="color: #66cc66">\n , c \n <span style="color: #66cc66">\n , d \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #ff4500">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Float
Float literals or floating-point literals contain numeric values in decimal points. We also sometimes call them by the name of real literals. Developers classify them into two main types:
- Fractional – contain whole numbers and decimal points.
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Fractional float literals\n \n \n \n \n \n \n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Positive\n \n \n x \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: #ff4500">\n 1090 \n \n \n <span style="color: #808080;font-style: italic">\n #Negative \n y \n <span style="color: #66cc66">\n = - \n <span style="color: #ff4500">\n 227 \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n ,y \n <span style="color: black">\n ) \n \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #ff4500">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
- Exponential – these values are represented in the powers of 10, represented by the letter e or E. The digits before the symbol E in an exponential literal are known as the mantissa and the digits succeeding the symbol E are the exponent. The exponent value describes the placement of the decimal point.
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Exponential float literals\n \n \n \n \n \n \n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Positive\n \n \n \n \n \n <span style="color: #ff7700;font-weight:bold">\n \n \n print\n \n \n <span style="color: black">\n ( \n <span style="color: #ff4500">\n 25.53E3 \n <span style="color: black">\n ) \n <span style="color: #808080;font-style: italic">\n #Decimal point will jump 3 places \n \n \n <span style="color: #808080;font-style: italic">\n #Negative \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (- \n <span style="color: #ff4500">\n 105.03E5 \n <span style="color: black">\n ) \n <span style="color: #808080;font-style: italic">\n #Decimal point will jump 5 places \n </span style="color: #808080;font-style: italic"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: black">\n \n \n </span style="color: #ff7700;font-weight:bold">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Complex
Complex literals are represented as X+Yj, where X is the real part of the value and Yj is the imaginary or complex part. Here, j= -1.
Consider the below examples of complex literals:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Complex literals\n \n \n \n \n \n \n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Positive\n \n \n \n \n \n <span style="color: #ff7700;font-weight:bold">\n \n \n print\n \n \n <span style="color: black">\n ( \n <span style="color: #ff4500">\n 12 + 8j \n <span style="color: black">\n ) \n \n \n <span style="color: #808080;font-style: italic">\n #Negative \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (-5j \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: black">\n \n \n </span style="color: #ff7700;font-weight:bold">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Best-suited Python courses for you
Learn Python with these high-rated online courses
String Literals
These literals contain textual data in the form of characters, enclosed within quotes. Based on quotes, we divide string literals into two subtypes:
- Single-line
- Multi-line
Let’s look at both of them in detail –
Single-line String Literals
Single-line string literals are enclosed within a single quote (‘ ‘) or double quotes (” “). Consider the below examples to understand how they work:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Single line string literals\n \n \n \n \n \n \n \n \n <span style="color: #ff7700;font-weight:bold">\n \n \n print\n \n \n <span style="color: black">\n \n \n (\n \n \n <span style="color: #483d8b">\n 'Python Tutorial' \n <span style="color: black">\n ) \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Shiksha Online" \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #483d8b">\n \n \n </span style="color: black">\n \n \n </span style="color: #ff7700;font-weight:bold">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Multi-line String Literals
Multi-line string literals are a collection of characters that span multiple lines. In Python, we can declare them in following in two ways:
- Backlashes – using a backlash at the end of each line.
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Multi-line string literals\n \n \n \n \n \n \n \n \n <span style="color: #008000">\n \n \n str \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: #483d8b">\n "Welcome \n <span style="color: #000099;font-weight: bold"> \n to \n <span style="color: #000099;font-weight: bold"> \n Naukri \n <span style="color: #000099;font-weight: bold"> \n Learning" \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n ( \n <span style="color: #008000">\n str \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #000099;font-weight: bold"> \n </span style="color: #000099;font-weight: bold"> \n </span style="color: #000099;font-weight: bold"> \n </span style="color: #483d8b">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #008000">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
- Triple quotes – you can also enclose multi-line strings in triple quotes (“””).
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Multi-line string literals\n \n \n \n \n \n \n \n \n <span style="color: #008000">\n \n \n str \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: #483d8b">\n """This \n is \n a \n Python \n Tutorial""" \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n ( \n <span style="color: #008000">\n str \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #483d8b">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #008000">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Boolean Literals
These literals take only two values: True (aka 1) and False (aka 0).
Let’s look at the below example:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Boolean Literals\n \n \n \n \n \n x \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: #ff4500">\n \n \n 1.0\n \n \n \n \n \n a \n \n \n <span style="color: #66cc66">\n = \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n == \n <span style="color: #ff4500">\n 1 \n <span style="color: black">\n ) \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "a is" \n <span style="color: #66cc66">\n , a \n <span style="color: black">\n ) \n \n b \n <span style="color: #66cc66">\n = \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n == \n <span style="color: #ff4500">\n 7 \n <span style="color: black">\n ) \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "b is" \n <span style="color: #66cc66">\n , b \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #66cc66">\n \n \n </span style="color: #ff4500">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Literal Collections
Developers use literal collections when they work with more than one value. They are of the following four subtypes:
- List literals
- Tuple literals
- Dictionary literals
- Set literals
Let’s look at each of them in detail –
List literals
We are already aware that lists are an immutable collection of different types of data. The elements of a list are separated by commas and enclosed in square brackets [].
Let’s look at the following example. Here, the list contains literals of different data types such as string, integer, float, dictionary, and a nested inner list:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #List Literals\n \n \n \n \n \n mylist \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: black">\n \n \n [\n \n \n <span style="color: #483d8b">\n 'Rosa' \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 10 \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'Jake' \n <span style="color: #66cc66">\n , - \n <span style="color: #ff4500">\n 2.3 \n <span style="color: #66cc66">\n , \n <span style="color: black">\n { \n <span style="color: #483d8b">\n 'Amy': \n <span style="color: #483d8b">\n 'Winner' \n <span style="color: black">\n } \n <span style="color: #66cc66">\n , \n <span style="color: black">\n [ \n <span style="color: #483d8b">\n 'Hitchcock' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'Sculy' \n <span style="color: black">\n ] \n <span style="color: black">\n ] \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (mylist \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n \n </span style="color: black">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Tuple literals
Tuples are similar to lists in the fact that they, too, are a collection of different types of data with elements separated by commas.
However, they differ from lists in two aspects – tuples are mutable, and they are enclosed in simple brackets ().
Let’s look at the following example. Here, we have created a tuple with collection literals of different data types such as string, integer, float, dictionary, and a nested inner list:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Tuple Literals\n \n \n \n \n \n tupe \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: black">\n \n \n (\n \n \n <span style="color: #483d8b">\n 'Rosa' \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 10 \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'Jake' \n <span style="color: #66cc66">\n , - \n <span style="color: #ff4500">\n 2.3 \n <span style="color: #66cc66">\n , \n <span style="color: black">\n { \n <span style="color: #483d8b">\n 'Amy': \n <span style="color: #483d8b">\n 'Winner' \n <span style="color: black">\n } \n <span style="color: #66cc66">\n , \n <span style="color: black">\n [ \n <span style="color: #483d8b">\n 'Hitchcock' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'Sculy' \n <span style="color: black">\n ] \n <span style="color: black">\n ) \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (tupe \n <span style="color: black">\n ) \n \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n \n </span style="color: black">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Dictionary literals
Dictionary literals store different types of data in a key-value format. These are enclosed in curly brackets {} and separated by commas. Dictionaries are mutable as well.
Let’s look at the following example of dictionary literals:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Dictionary Literals\n \n \n \n \n \n mydict \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: black">\n \n \n {\n \n \n <span style="color: #483d8b">\n 'a': \n <span style="color: #483d8b">\n 'apple' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'b': \n <span style="color: #483d8b">\n 'ball' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'c': \n <span style="color: #483d8b">\n 'cat' \n <span style="color: black">\n } \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (mydict \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #483d8b">\n \n \n </span style="color: black">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Set literals
Set literals are a collection of unordered data. These are enclosed in curly brackets {} and separated by commas. Sets are immutable.
Let’s look at the following example of set literals:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Set Literals\n \n \n \n \n \n vowelset \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: black">\n \n \n {\n \n \n <span style="color: #483d8b">\n 'a' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'e' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'i' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'o' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'u' \n <span style="color: black">\n } \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Vowels: " \n <span style="color: #66cc66">\n , vowelset \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n \n </span style="color: black">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Special Literal
Python has a special literal known as None. It signifies that a particular field is not created. Developers can also use it for end of Python lists.
Let’s look at the below example:
\n \n \n <pre class="python" style="font-family:monospace">\n \n \n <span style="color: #808080;font-style: italic">\n \n \n #Special Literal\n \n \n \n \n \n my_list \n \n \n <span style="color: #66cc66">\n \n \n = \n \n \n <span style="color: black">\n \n \n [\n \n \n <span style="color: #483d8b">\n 'Dog' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'Cat' \n <span style="color: #66cc66">\n , \n <span style="color: #008000">\n None \n <span style="color: black">\n ] \n \n \n <span style="color: #ff7700;font-weight:bold">\n print \n <span style="color: black">\n (my_list \n <span style="color: black">\n [ \n <span style="color: #ff4500">\n 2 \n <span style="color: black">\n ] \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n \n </span style="color: black">\n \n \n </span style="color: #66cc66">\n \n \n </span style="color: #808080;font-style: italic">\n \n \n </pre class="python" style="font-family:monospace">
Output:
Endnotes
I hope this article was helpful for you to understanding literals in python and how to implement different types of literal. You can explore related articles here if you wish to learn more about Python and practice Python programming.
Explore programming courses
Check out more Trending Article on Python
Top Online Python Compiler | How to Check if a Python String is Palindrome | Feature Selection Technique | Conditional Statement in Python | How to Find Armstrong Number in Python | Data Types in Python | How to Find Second Occurrence of Sub-String in Python String | For Loop in Python |Prime Number | Inheritance in Python | Validating Password using Python Regex | Python List |Market Basket Analysis in Python | Python Dictionary | Python While Loop | Python Split Function | Rock Paper Scissor Game in Python | Python String | How to Generate Random Number in Python | Python Program to Check Leap Year | Slicing in Python
Recently completed any professional course/certification from the market? Tell us what liked or disliked in the course for more curated content.
Click here to submit its review.
This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio