Quantcast
Channel: #! code - Python
Viewing all articles
Browse latest Browse all 4

Multi-line Comments In Python

$
0
0

Python doesn't officially support multi-line comments, but there is a way of implementing the same functionality using an existing language construct. Single line comments in Python are written like this:

1
# This is a single line comment.

You can create a multi-line comment in Python by using a multi-line string. Unless it is part of a docstring at the start of a class, function or module then it is ignored.

1
2
3
4
5
'''This isa multilinecomment'''

Multi-line strings are used when you want to create a string that is split across several lines. If you create one and don't assign it to a variable then it is just thrown away. Multi-line strings can be used in the following way.

1
2
3
4
5
6
multilinestring ='''This isa multilinestring'''print multilinestring
Category: 
Tags: 

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images