Computer >> Computer tutorials >  >> Programming >> Python

What is the difference between single and double quotes in python?


A string as a sequence of characters not intended to have numeric value. In Python, such sequence of characters is included inside single or double quotes. As far as language syntax is concerned, there is no difference in single or double quoted string. Both representations can be used interchangeably. However, if either single or double quote is a part of the string itself, then the string must be placed in double or single quotes respectively.

Example

For example a text Hello “Python” is to be stored as a string, then one should use

str1='Hello "Python"'

On the other hand, if string should resemble Hello ‘Python’ then it should be declared as follows:

Str2="Hello 'Python'"