When I use single quotes to represent a string, and there are single quotes in the string, we can represent these single quotes by escaping characters. If you want to represent the string Let's go, it must be like this:
s4 = 'Let\'s go',
There is a ' in the string, and the string is represented by ', so you need to use it at this time Escape character \ , if there are a lot of escape characters in the string, it will look very messy. Python also solves this problem very well, as follows:
s5 = "Let's go"
python knows you " is used to represent a string, so python treats the single quotes in the string as ordinary characters. Isn't it very simple?
The same is true for double quotes. Here is an example
s6 = 'I really like "python"!'
This is why both single quotes and double quotes can represent strings.
For more Python-related technical articles, please visit Python TutorialColumn for learning!
The above is the detailed content of How to enter single quotes in python. For more information, please follow other related articles on the PHP Chinese website!