Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#PYTHON#8177 Back

string variations

Python allows you to define the literal form of strings in either single quote (‘) or double quote (“”). Both have similar meaning. We are also allowed to give triple single quotes (”’) for string literals which can be run into many lines. 

 

Source Code

		 

Click to open popup

Run Output

INDIA IS A PART OF ASIA.
CAPITAL OF INDIA IS:
NEW DELHI
I adore 'Python'
I love "Python"

Notes

  • Strings defined with single quote ‘ on both sides or double quote ” on both sides are the same.
  • One can define a multi-line string using triple single quote ”’ . This works as a string when assigned to a variable.
  • Triple single quote is also used as multi-line comment as depicted in example 3 earlier.
  • Within single quote literal construct, double quotes can be directly given. Similarly within double quote construct, single quote can be given. For e.g. ‘Say “Hello” to me’ is valid and “Say ‘Hello’ to me” is also valid.