Python (CMIS 102)

Learning python creates possibilities to manipulate computers for a myriad of tasks. The power python provides the user, coupled with the easy learning experience, makes it a lucrative programming language to learn. Let’s get started with some of the basics that I learned in the UMGC CMIS 102 course which is introduction to the python programming language. 

Topic 1: print statement

The first thing you learn when you pursue the python programming language is the print statement as well as how the code editor works. In the first programming course (CMIS 102) at University of Maryland Global Campus the introduction starts off similar to many online courses and Youtube videos do with the classic “Hello World!” print statement as illustrated below. They also suggested we used IDLE the python interpreter which is the code editing suite. 

The latest version of python3 can be downloaded here.

				
					print("Hello World!")
				
			
				
					Output from code above ^

Hello Wold

				
			

Python is the debatably the most popular programming language. It has a great number of applicable use cases: software development, web applications, data science, game development, and even A.I. applications. Moreover python is a readable language which means that as you read the code you can generally understand what is supposed to happen when the code is executed. Another benefit is that the library python comes with is paramount to the programming languages ease of implementation. The built in functions allow for automation for crucial time saving tasks. Have I sold you yet? 

There are plenty of great books to get started but I recommend these for an ethical hacker focused learning approach.

1.) Learning Python by Mark Lutz

2.) Introducing Python (Modern Computing in Simple Packages) by Bill Lubanovic

3.) Automate The Boring Stuff With Python by Al Sweigart

4.) Black Hat Python (Python Programming for Hackers and Pentesters) by Justin Seitz

5.) Violent Python (A Cookbook for Hackers, Fornesic Analysts, Penetration Testers, and Security Engineers) by TJ O’Connor

Topic 2: Variables

Variables in python are awesome. They are mutable which means that the variables can be changed and updated throughout whatever program you are designing. You can take a word and assign any value to it. Values can be any data type. What are data types you might ask? Simple data types can be, strings (“string”) or integers (0-9). There are many more but let’s keep it super simple for now.  

data types:

str() = (“Any word or set of words between quotes”)

int() = (1)

float() = (1.2)

bool() = TRUE or False | a.k.a. binary would be True =1 & False = 0

 

				
					FOOD = pizza
print("Yesterday I ate",FOOD)

sexy_time = (69)
print("My favorite number is",sexytime)
				
			
				
					Output from code above ^

Yesterday I ate pizza
My favorite number is 69
				
			

As you can see the print statement is not displayed in the bottom box when the code is ran. The variable food when used within the print statement displays the assignment factor and not the actual variable. The same goes for the variable sexytime which had the number 69 assigned to it. 69 was displayed as my favorite number instead of the word/variable sexytime. 

The syntax has been illustrated for a few variables containing different data types now in a fun manner.

Topic 3: Boolean Expressions

Truth or Dare….

Just kidding! Boolean Expressions are evaluated as any number being True except 0. Boolean expressions use mathematical symbols to logically compare data types.

Another important note is that using the hashtag is a way to input comments into the program. Comments are not read by the program when executed or ran. Comments are there to indicate to anyone else reading the code an explanation for how the code works or what the code is supposed to do when something may be unclear.

Comparison Operators:

X != Y           # X is not equal to Y        <—This would be considered a comment since the explanation is preceded by a hashtag

X > Y            # X is greater than Y

X < Y            # X is less than Y

x >= Y          # X is greater than or equal to Y

X <= Y         # X is less than or equal to Y

				
					print(10 != 100)
print(1 > 0)
print(1 < 10)
print(10>=10)
print(10<=11)

print(1 < 0)
print(10 != 10)
				
			
				
					Output from code above ^

True
True
True
True
True
False
False

				
			

The output of the boolean expressions is either True or False. Hopefully that is illustrated through the expressions above.

Topic 4: Loops

Loops are an essential feature in the python language that allows the user to parse through a list or to create a loop that ends when a certain condition is met. 

There are two types of loops. For Loops & While Loops.

A For Loop iterates a number of times specified by the range. 

A While Loop repeats the execution of statements until the determination of a condition returns True or False.

Understanding the use of Loops is best experienced rather than explained. 

				
					#While Loop Example

a = 0 #Define a variable
b = 10 #Define b variable

#Create While Loop 

while a < b:
    print(a)
    a = a + 1
    


				
			
				
					Output from code above ^

0
1
2
3
4
5
6
7
8
9

				
			

As you can see from the output from the code above each line outputs a number that is incremented 1 more than the previous number until a < b which would be 9 < 10 as True. So the While Loop is infinite until the condition which we set becomes False.

				
					#For Loop Example

breakfast = ["spam","eggs","ham"]

#Create For Loop 

for food in breakfast:
    print(food)
    


				
			
				
					Output from code above ^

spam
eggs
ham
				
			

The code above uses what’s called an iteration variable which in this case is “food” to iterate through the elements in the list. It printed each element that was assigned to the variable breakfast. This is a very simple for loop that produces a simple output.

Topic 5: Array

Array is defined most simply as a sequence of values and is sometimes called a list. The values can be any data type and are referred to as elements or items. The easiest way to create an array is to enclose your elements or items within a set of [brackets]. It is important to note that arrays start with 0 when you count elements/items from the left hand side always. so even though you may have 5 items in a list, when you count the items it will be from 0,1,2,3,4 elements total. 

				
					#Array Example

a = [1,2,3] # How many elements here? 0...1....2
b = [4,5,6]
c = a + b
print(c)  #How many elements will c print out? 0,1,2,3,4,5
print[0](c * 4) #Here we are telling python to print the first item in the list of c 4 times


    


				
			
				
					Output from code above ^

1,2,3,4,5,6
1111 
				
			

FAQ

Most frequent questions and answers

The best way to begin is to get started programming basic applications yourself. You can start by going to Python.org and downloading the language and interpreter IDLE.

It is a lucrative skill to be able to program. The use cases for python in real world scenarios are infinite. It is a stepping stone to overcome the script kiddie lifestyle that so many middle level hackers plateau at.

Python is a free language to download with guides a plenty all over the internet to include Youtube and a plethora of free blog posts that can get you started.

My opinions are biased because I really enjoy David Bombal & Network Chuck.

~Disclaimer ALERT

David Bombal teaches python for network engineers primarily and Network Chuck doesnt do deep dives into python rather he provides a general overview of topics very similar to this entire blog post. It is more of an introduction into topics to hopefully spark interest in the subject. 

Resources

Team Tree House

Free Code Camp Online

keyboard, computer, technology-5017973.jpg