Skip to content

Lines, Quotation & Comments

Lines :-

Python Statements typically end with a new line. If you want to continue the line, you need to use line continuation character (\) to denote that the line should continue. For example −

>>> a="abc bdc"
>>> C="jj"
>>> f=a
>>> f
'abc bdc'
>>> f=a + \
>>> f
'abc bdcjj'

In the above example, we can see after defining f=a , if we press enter then f contains the value of a. So, if you want f to contain the value of both a & c in the same line, you need to use (\) as specified above (highlighted). Using (\) & pressing enter will not come out of the statement instead it will expect user to enter something which can be appended to original value (in this case a)

Statements contained within the [], {}, or () brackets do not need to use the line continuation character.

days = [‘Monday’, ‘Tuesday’, ‘Wednesday’,
‘Thursday’, ‘Friday’]

Quotation :-

Python accepts single (‘), double (“) and triple (”’ or “””) quotes to denote string literals, as long as the same type of quote starts and ends the string.

The triple quotes are used to span the string across multiple lines

word = ‘word’
sentence = “This is a sentence.”
paragraph = “””This is a paragraph. It is
made up of multiple lines and sentences.”””

Comments :-

A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and the Python interpreter ignores them.

# First comment
print "Hello, Python!" # second comment

You can comment multiple lines as follows

# This is a comment.
# This is a comment, too.
# This is a comment, too.
# I said that already.


Leave a Reply

%d bloggers like this: