Python – Create String using Double Quotes

Create 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"

Python Program

x = "sample\" text"


sample" text