Python – Create String using Single Quotes

Create String using Single Quotes

To create or define a string in Python using single quotes, enclose the string value or literal in single 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 single quotes, if we would like to use single quote inside this string, we must escape the single quote using backslash character.

'user\'s world'

Python Program

x = 'user\'s world'


user's world