Create a string using double quotes
To create or define a string in Python using double quotes, enclose the string value or literal in double quotes.
"hello world"
We can assign this string value to a variable.
x = "hello world"
We can use the string literal in an expression, say concatenation of two strings.
x = "hello world" + "apple"
Since we defined the string using double quotes, if we would like to use a double quote inside this string, we must escape the double quote using backslash character.
"sample\" text"
Example
In the following program, we create a string using single quotes, and print it to console.
Python Program
x = "sample\" text"
print(x)
Run Code Online Output
sample" text
Summary
In this tutorial of Python Examples, we learned how to create a new string value using double quotes.
⫷ Previous tutorialNext tutorial ⫸