Category Archives: Programming

Learning Python – Lesson 2: Comments and Math!

python math

In this post, we will examine two great features we can begin using in our amazing Python applications. The first is the ability to use the pound sign (#) in order to add comments to our code.

This, of course, makes our code more “self-documenting”. This is a fancy term for us being able to figure out what the hell the code is supposed to do if we wrote it a long time ago and forgot! It is also nice to have this done in the event we ship our code off to a peer that needs to understand what we are up to.

# This is an entire line of code that is not going to run in this application.
# It is just here for our documentation purposes.
print "Here is the print command at work that we used in an earlier lesson."
print "And here is another cool way to use it!" # This will not print even though it is in the same line of code!

Let me save this masterpiece as and run it! Today I am using the Python download for Windows because I cannot find my MacBook! 🙂

C:\Users\terry> python C:\Users\terry\OneDrive\Blog\Python\
Here is the print command at work that we used in an earlier lesson.
And here is another cool way to use it!


Now let’s turn our attention to math – here are the math operators we have at our disposal!

+     plus
-     minus
/     slash
*     asterisk
<     less-than
>     greater-than
<=   less-than-equal
>=   greater-than-equal

Now it is time for me to create and have some fun with math!

print "How much I tip in USA for poor service on $100 = $", 100 * .15
print "If the service is good on $100 = $", 100 * .18
print "If the service is awesome on $100 = $", 100 * .20
print "My age is shown below!" 
print 40 + 9

Now it is time to run it!

C:\Users\terry>python C:\Users\terry\OneDrive\Blog\Python\
How much I tip in USA for poor service on $100 = $ 15.0
If the service is good on $100 = $ 18.0
If the service is awesome on $100 = $ 20.0
My age is shown below!

I hope you will return for some more Python fun soon!

Remember, various Python courses are waiting for you at CBT Nuggets! If you are not a member, no worries, sign up for a FREE WEEK and start training today!

Learning Python – Lesson 1: Getting Started!

Why Do This?

Python is a simple programming language capable of big things. It features wide support across network devices.

There are many reasons you should consider learning Python – here are just some of them:

  • It is fun!
  • You might not have learned a programming language in a long, long time.
  • Python is often used in Software Defined Networking (SDN) Environments.
  • Did I mention it is fun?
  • Python is now a requirement for many professional certifications from companies like Cisco, Juniper, AWS, and more

The First Application

I hope you enjoy my notes on my learning here at I am using various resources to help you, but the primary one I would love for you to follow along with is the CBT Nuggets course:

Python Programming

I am on a Mac – which provides the luxury of having Python built right in (just like Linux). For those of you on Windows – head over to

For composing my Python applications – I am using the BBEdit from After thirty days of the full version, you can continue to use it free for your text editing work. Advanced functionality like Web authoring goes away, but no big deal for me.

I will use BBEdit to create my first Python application! How exciting. 🙂 Here it is.

print “Hello World!”

print “This is awesome!” 

print “I am a programmer!”

I will save this complex program 😉 as a file named

I will now run this application in the Terminal application in Mac OS. This is done with the command:

python Python

Make sure you are in the directory where that file exists of course!

Interested in what version of Python you are running?

Try this command:

python –version

I just discovered I am running Python 2.X.

Final Thoughts

This is an excellent time to practice with some of your directory and file management skills from within Terminal. I found myself using the following commands in this first application and its execution:

  • mkdir – Make a directory
  • cd – Change directory
  • ls – List the contents of a directory

Thanks for reading and I hope your first Python application was a success as well.

Do you have questions? We are standing by – just use the comments area below.