How to create string using double quotes?


Python - Create a string using double quotes

To create a string using double quotes in Python, enclose the required string value or sequence of characters in double quotes.

For example, consider the following string created using double quotes.

"hello world"

We can assign this string value to a variable, say x, as shown in the following.

x = "hello world"

We can use the string literal in an expression, say concatenation of two strings.

"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 Example to create a string using double quotes

In the following program, we create a string using double quotes, assign the string to a variable, and print the string to standard console output.

Python Program

x = "sample\" text"
print(x)

Output

sample" text

Video Tutorial

In the following video tutorial, you shall learn how to create a string in Python with well detailed explanation and examples.

https://youtu.be/2hexxE0d39s

Summary

In this tutorial, we have seen how to create a new string value using double quotes in Python, with well detailed examples.