Coding in Python 10 - Comments and Style

From LearnLinux.tv Wiki
Jump to navigationJump to search

Overview

In video number 10 of the Coding in Python series, we take a look at various forms of comments, and some guidelines regarding style.

Relevant Links
Original Video
Python Enhancement Proposals
PEP Article regarding Comments


Commands Used in this Video

Comment

#!/usr/bin/python3

# This is a comment.

print("This is NOT a comment.")

In-line comment

#!/usr/bin/python3

myvar = 3  # This is a variable

print(myvar)

Multi-line comment

#!/usr/bin/python3

# This is
# a
# multi-line
# comment

Documentation String

""" This program is intended to do something really neat.
This is version 1.0.
This program may be useful, some day.
"""

print("This is a string.")

Commenting out a String

#!/usr/bin/python3

print("This program will fail.")

#my var1 = 3
myvar2 = 2
myvar1 = 5

print(myvar1)
print(myvar2)