Python String Literals

A string is literal and can be created by writing a text(a group of Characters ) surrounded by a single(”), double(“), or triple quotes.  We can write multi-line strings or display them in the desired way by using triple quotes. Here geekforgeeks is a string literal that is assigned to a variable(s). Here is an example of a Python string literal.

Python3




# in single quote
s = 'geekforgeeks'
 
# in double quotes
t = "geekforgeeks"
 
# multi-line String
m = '''geek
           for
               geeks'''
 
print(s)
print(t)
print(m)


Output

geekforgeeks
geekforgeeks
geek
for
geeks

Literals in Python

A literal in Python is a syntax that is used to completely express a fixed value of a specific data type. Literals are constants that are self-explanatory and don’t need to be computed or evaluated. They are used to provide variable values or to directly utilize them in expressions. Generally, literals are a notation for representing a fixed value in source code. They can also be defined as raw values or data given in variables or constants. In this article, we will explore the different types of literals in Python, along with examples to demonstrate their usage.

Literals in Python

Similar Reads

Types of Literals in Python

Python supports various types of literals, such as numeric literals, string literals, Boolean literals, and more. Let’s explore different types of literals in Python with examples:...

Python String Literals

A string is literal and can be created by writing a text(a group of Characters ) surrounded by a single(”), double(“), or triple quotes.  We can write multi-line strings or display them in the desired way by using triple quotes. Here geekforgeeks is a string literal that is assigned to a variable(s). Here is an example of a Python string literal....

Python Character literal

...

Python Numeric literal

It is also a type of Python string literal where a single character is surrounded by single or double quotes....

Python Boolean literal

...

Python literal collections

They are immutable and there are three types of numeric literal:...

Python Special literal

...

Contact Us