Python string literals

Python strings can be created with single quotes, double quotes, or triple quotes. When we use triple quotes, strings can span several lines without using the escape character.

Python string literals example

In the following example, we assign three string literals to the a, b, and c variables. And we print them to the console.

Create a string_literals.py file and add the following content to it:

#!/usr/bin/env python

# string_literals.py

a = "source code examples"
b = 'python code examples'
c = """
source 
code
examples
"""

print(a)
print(b)
print(c)

Output:

source code examples
python code examples

source 
code
examples


Comments