Learning Python – Variables

February 12, 2017 at 10:09 pm

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!

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!

Learning Python – Comments and Math in your Apps!

January 9, 2017 at 10:32 pm

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.
 # Anything after the # is ignored by Python!
 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 ex2.ps 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\ex2.ps
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
%     percent
<     less-than
>     greater-than
<=   less-than-equal
>=   greater-than-equal

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

print "This is how much I like to tip when the service in the US at a restaurant is poor and the tab is $100 - ", 100 * %15
print "If the service is good - ", 100 * %18
print "If the service is awesome - ", 100 * %20
print "My age is shown below!" 
print 40 + 7

Now it is time to run it!

C:\Users\terry>python C:\Users\terry\OneDrive\Blog\Python\ex3.ps
This is how much I like to tip when the service in the US at a restaurant is poor and the tab is $100 - 15.0
If the service is good - 18.0
If the service is awesome - 20.0
My age is shown below!

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

Learning Python – Getting Started!

January 1, 2017 at 11:45 am

Why Do This?

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

There are many reasons that I have decided to learn Python – here are just some of them:

  • It is fun!
  • I have not 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?
  • I want to really branch out in my IT skill set in 2017.

The First Application

I hope you enjoy my notes on my learning here at AJSNetworking.com. I am using the fun text – Learn Python the Hard Way.

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!

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 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.