Tag Archives: learning

Learning Python – Lesson 3: Introducing Variables

Free Python Training

We all know that variables are a key part of programming and scripting languages, and sure enough, they are a big part of Python. Here is how simple they are to implement:

#Today we are going to create and use some variables! 
#This is really cool! 
#Hey just to remind you, these are comments that are here to make our code "self-documenting"! 
#Python itself is ignoring the s#$t out of these! 
my_books = 14
my_years_on_planet = 47
books_per_year_on_planet = my_books / my_years_on_planet
print ("Below is my books per year on the planet!")
print (books_per_year_on_planet)

Notice here I am using Python 3 so I need parenthesis around the objects and text that I want to print instead of the older quotation marks! This is the most noticeable difference between Python version 2 and version 3. The PRINT function got a nice little update in this regard.

Here is the result of my program!

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
======================= RESTART: C:\Users\terry\ex3.ps =======================
Below is my books per year on the planet!

If you are you are using Python 2, you need the “older” syntax to make those print functions work right. Here is that version of our code for you:

#Today we are going to create and use some variables! 
#This is really cool! 
#Hey just to remind you, these are comments that are here to make our code "self-documenting"! 
#Python itself is ignoring the s#$t out of these! 
my_books = 14.0
my_years_on_planet = 47.0
books_per_year_on_planet = my_books / my_years_on_planet 
print "Below is my books per year on the planet!" 
print books_per_year_on_planet

Notice another change here – I need to indicate my variables are of the Float type in order to display my result in the format I need. So I enter my 14.0 and 47.0 for the variable values. I will discuss this in greater detail in the next post!

One final note, if you wanted to use the print function so that it would work in both version 2 and version 3, you would want to use both the ( and the ” as I did in the first program above. For example, I am using Python 2 now:

print ("Hello World!")

This returns:

Hello World!

just as it would in Python 3.

Remember, free Python training is waiting for you at CBT Nuggets!

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 AJSNetworking.com. 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 python.org/download.

For composing my Python applications – I am using the BBEdit from BareBones.com. 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 ex1.py.

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

python ex1.py 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.

Things I Learned Training for a Half Marathon

Training Over
Finish line a few feet ahead!

“The Best Part Was the Training”

Talk to marathon and half marathon runners and you will often here this phrase. Yes, that’s right – they LOVED training for it. The event itself, well, that might be kind of exciting and incredible as well, but it might not matter as much since you train for months and months and you LOVE doing that. And I suppose that is the first lesson isn’t it. We need to make sure we love the training process. If you are not loving the training, then figure out exactly why you are not and get ready to fix that. I hope these other tips I picked up and learned along the way will help you as well. And of course this goes for whatever goal you are trying to achieve.

Track Your Training

This is one you have probably heard me talk about before. With my classes at CBT Nuggets, I even include trackers for the students to use as they move through the course.  For me, tracking became an obsession, and this obsession proved very motivating. Also, in the specific area of distance running it was very necessary since I had to find the perfect pace at which I would have a chance to complete the actual race.

Find a Training Buddy

I would not have succeeded in this endeavor without a training buddy. Someone to push me, hold me accountable, discuss ideas with, etc. By the way, that is my training buddy pictured above! When we started, I was better at running and really enjoyed it much more than her. As you can see from that finish line shot, that all changed!

Add Fun!

When I would run with my buddy, we would chat. And you know me, I love to chat. When running by myself I would add music. I am so busy, there is often never time to check out some latest album. These solo runs, which I might have really disliked, became fun with music added.

Join a Community

OK, I never joined a runner’s community, but I lurked at a bunch of them. Getting questions answered that were crucial for my success.

Don’t Let Jerks Get You Down

If you are into social media, or in a community of people online, you are going to run into jerks and trolls, it just happens. When people are hiding behind a keyboard, they can become pretty callous and mean. To add a problem, many times someone will sound like a jerk when they are actually not trying to act like that. During my training, someone posted on Twitter in response to one of my training posts that included statistics on a run – “You know you are not running right? You are jogging!” While I thought about getting angry about this, I just blew it off.

Get Excited for the Next Goal!

While there was some amount of “thank God that is over!”, after the race I became very excited about the future and more health goals. This thing had kicked weight loss into overdrive. I lost 14 pounds over the course of training and the race. Not bad. Now I can really up fitness goals of the future…

Thanks for reading, and remember, LOVE your training!

Cisco CCIE Lab Builder