Page 61 - Python Basics: A Practical Introduction to Python 3
P. 61
3.6. Summary and Additional Resources
the code and the # symbol:
phrase = "Hello, World" # This comment is PEP 8 compliant.
print(phrase)# This comment isn't.
PEP 8 recommends that comments be used sparingly. A major pet
peeve among programmers is comments that describe what is already
obvious from reading the code.
For example, the comment in the following code is unnecessary:
# Print "Hello, World"
print("Hello, World")
The comment is unnecessary because the code itself explicitly de-
scribes what’s happening. Comments are best used to clarify code
that may be difficult to understand or to explain why something is
coded a certain way.
3.6 Summary and Additional Resources
In this chapter, you wrote and executed your first Python program!
You wrote a small program that displays the text "Hello, World" using
the print() function.
Then you learned about syntax errors, which occur before IDLE ex-
ecutes a program that contains invalid Python code, and runtime
errors, which only occur while a program is running.
You saw how to assign values to variables using the assignment
operator (=) and how to inspect variables in the interactive window.
Finally, you learned how to write helpful comments in your code for
when you or someone else looks at it in the future.
60