Skip to content

Instantly share code, notes, and snippets.

@jesselawson
Last active December 31, 2019 19:15
Show Gist options
  • Save jesselawson/4f1c4956f65314984638ad7341b6bfb3 to your computer and use it in GitHub Desktop.
Save jesselawson/4f1c4956f65314984638ad7341b6bfb3 to your computer and use it in GitHub Desktop.
"""
Example 2
Introducing both kinds of comments, and using them to explain in detail the
elements of Example 1.
"""
# A 'comment' is code that is ignored by a language's compiler or interpreter.
# Python ignores any line that starts with the octothorpe (`#`).
# You might be more familiar with the term 'hash' or 'pound sign' for the # character.
"""
Another way to write comments is by surrounding a block of text with three
quote characters--three on top, and three on the bottom.
Multi-line comments are useful when you have a LOT of text to write and don't
want to put a # symbol in front of every single line.
It doesn't matter which kind of comment syntax you use, but generally speaking,
use the octothorpe symbol for single-line comments and the triple-quote comments
for multi-line comments.
"""
"""
The 'import' statement is used to import functionality from a 'module' called
'sys' (short for 'system'). The 'sys' module provides some very low-level
information about Python's interpreter, and lets us use the sys.exit()
function later.
"""
import sys
# This block "defines" (def) a function named 'main'. We know it's a function
# because it has the parentheses ( and ).
def main():
# Note how we indented here. This means that anything at this level of
# indentation is part of the 'main' function's scope.
# The print function simply prints a string to the window where we are running
# the Python interpreter.
print("Hello, World!")
# Because the below print statement is commented out, it will not execute.
# print("I am a donut")
# Comments do not follow indentation/scope rules, but it's a good idea to
# keep them indented with the scope in which you are making the comment.
# Comments
# like
# this
# are
# technically legal,
# but will make
# everyone around you
# very frustrated!
"""
Below is a standard application initialization block of code, found in
thousands of files across thousands of applications. It's purpose is to
pass the main function of our program into Python's sys.exit() function, which
allows Python to 'catch' errors in a more efficient manner.
You do not need to understand this yet, but you should be familiar with it--
you will be seeing it a lot!
Learn more on your own: https://stackoverflow.com/a/5280221
"""
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment