Change language

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!" )


 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.


Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method

# 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 "’ )