Example # 1:
Check the example below and analyze the error —
#Gives Error print (`It`s python`) pre >
This gives an invalid syntax error. Because the single quote after "it" is considered the end of the line and the rest is not part of the line.
This can be fixed as:
Example # 2:
If you want to print & # 39; WithQuotes & # 39; in Python, this cannot be done only with single (or double) quotes, this requires the use of both at the same time.
"` WithQuotes` "
"Hello` Python` "
`" WithQuotes "`
`Hello" Python "`
`WithQuotes` Hello` Python` "WithQuotes" Hello "Python"
The choice between both types (single and double quotes) depends on the programmer`s choice. Typically, double quotes are used to represent strings, and single quotes are used for regular expressions, dict keys, or SQL. Hence, both single quotes and double quotes represent a string in python, but sometimes we need to use one type on top of the other.
Get Solution for free from DataCamp guru
Submit new EBook