+

Single and double quotes | python

Example # 1:
Check the example below and analyze the error —

 #Gives Error print (`It`s python`)  

Explanation —
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:

print ( "It`s Python!" )

Exit:

 It`s Python! 

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.

Exit —

 `WithQuotes` Hello` Python` "WithQuotes" Hello "Python" 

Output —
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

# this code prints the output in quotes.
# print WithQuotes in single quotes

print ( "` WithQuotes` " )

print ( "Hello` Python` " )

 
# print WithQuotes in single quotes

print ( `" WithQuotes "` )

print ( `Hello" Python "` )