How to create string using single quotes?
Python - Create a 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 Example to create a string using single quotes
In the following program, we create a string using single quotes, assign the string to a variable, and print it to standard console output.
Python Program
x = 'hello world'
print(x)
Output
hello world
Video Tutorial
In the following video tutorial, you shall learn how to create a string in Python with well detailed explanation and examples.
Summary
In this tutorial of Python Examples, we learned how to create a new string value using single quotes.