Python // Lesson 0: Prework

  1. Introduction 
    Length is 7 minutes
  2. Why Learn Programing?
    Length is 1 minute
  3. Why Python?
    Length is 3 minutes
  4. Python2 versus Python3
    Length is 2 minutes
  5. Characteristics of Python
    Length is 5 minutes
  6. The Python Interpreter Shell
    Length is 9 minutes
  7. IPython
    Length is 4 minutes
  8. Printing to stdout and Reading from stdin
    Length is 6 minutes
  9. Dir, Help, and Variables
    Length is 10 minutes
  10. Python Strings (Part 1)
    Length is 6 minutes
  11. Python Strings (Part 2)
    Length is 8 minutes
  12. Python Strings (Part 3)
    Length is 10 minutes
  13. Python String Formatting (Part 1)
    Length is 12 minutes
  14. Python String Formatting (Part 2)
    Length is 4 minutes 

Additional Content:

Google Python Course on Strings

Automate the Boring Stuff with Python (Chapter 6 on Strings)     
*Read up through the section on .join() and .split() string methods.


1. Python naming conventions:

    a. For variable names, function names, object names, and module names use lower case separated by underscore, for example:


    b. For class names, capitalize the first letter of each word.  Do not use any underscores.  For example:


    c. For constants, use all upper case; use underscores for word separation.

      PI = 3.14


Reference code for these exercises is posted on GitHub at:

1. Create a Python script that has three variables: ip_addr1, ip_addr2, ip_addr3 (representing three corresponding IP addresses). Print these three variables to standard output using a single print statement.

Make your print statement compatible with both Python2 and Python3.

If you are using either Linux or MacOS make your program executable by adding a shebang line and by changing the files permissions (i.e. chmod 755

2. Prompt a user to enter in an IP address from standard input. Read the IP address in and break it up into its octets. Print out the octets in decimal, binary, and hex.

Your program output should look like the following:

​ $ python 
Please enter an IP address:

    Octet1         Octet2         Octet3         Octet4     
      80             98             100            240      
   0b1010000      0b1100010      0b1100100     0b11110000   
     0x50           0x62           0x64           0xf0      

Four columns, fifteen characters wide, a header column, data centered in the column.

3.   Create three different variables the first variable should use all lower case characters with underscore ( _ ) as the word separator. The second variable should use all upper case characters with underscore as the word separator. The third variable should use numbers, letters, and underscore, but still be a valid variable Python variable name.

Make all three variables be strings that refer to IPv6 addresses.

Use the from future technique so that any string literals in Python2 are unicode.

compare if variable1 equals variable2
compare if variable1 is not equal to variable3

4. Create a show_version variable that contains the following

 show_version = "*0        CISCO881-SEC-K9       FTX0000038X    " 

Remove all leading and trailing whitespace from the string.

Split the string and extract the model and serial_number from it.

Check if ‘Cisco’ is contained in the model string (ignore capitalization).

Check if ‘881’ is in the model string.

Print out both the serial number and the model.

5. You have the following three variables from the arp table of a router:

mac1 = “Internet           94   5254.abbe.5b7b  ARPA   FastEthernet4”
mac2 = “Internet            3   5254.ab71.e119  ARPA   FastEthernet4”
mac3 = “Internet          231   5254.abc7.26aa  ARPA   FastEthernet4”

Process these ARP entries and print out a table of “IP ADDR” to “MAC ADDRESS” mappings. The output should look like following:

             IP ADDR          MAC ADDRESS
-------------------- --------------------       5254.abbe.5b7b       5254.ab71.e119       5254.abc7.26aa

Two columns, 20 characters wide, data right aligned, a header column.