• Category
  • >Python Programming

First Step Towards Python

  • Priyanshu Gupta
  • Jan 13, 2021
First Step Towards Python title banner

Prerequisite :

 

  • Operating System Windows & Linux

  • 4 GB RAM 

  • Internet Connection

  • Basic Knowledge of Linux

 

Python proudly holds the position as one of the world’s most popular programming languages. In most of the domains, it is giving its share. Employing python allows the user to work on multiple domains ranging from Data Science, Machine Learning, Deep Learning, Artificial Intelligence, Scientific Computing Scripting, Networking, Game Development to Web Development. Owing to the programming language’s multiple domain integrity, it is greatly loved by communities. 

 

Python contains Domain-Specific Libraries. Stay tuned with us as we go through the multiple domains of development.

 

 

Who Created Python?

 

  • Guido Van Rossum is the man behind the creation of the Python Programming Language. He was born in 1956 in Haarlem in the Netherlands. 

  • The name Python came from an Old BBC television comedy sketch series called “Monty Python Flying Circus”.

  • While various programming languages have been generated by large corporations equipping themselves with numerous experts and professionals, Python is an Exception.


 

 

What is Python?

 

Do you think it is a Snake? Actually not.      

In the Computer World, Python is a Programming Language. It’s used for fulfilling demands of :

 

  • Interpreted Programming Language: In this language, the Interpreter always runs & checks Codes Line by Line.

  • Object-Oriented Programming Language: In this language, an Object (abstract data type) integrates State (data) & Behaviour (code).

  • High-Level Programming Language: It is a Programming Language that does not depend on any particular type of Computer Machine to write Codes.

  • General Purpose Programming Language: It is a Programming Language that is designed to be used in a wide variety of domains.

 

 

Overview:

 

In order to start our journey, let’s get familiar with the environment in which we are going to implement Python Programming. Here, we will consider different environments for different domains of development that are available on the Internet. 

 

Python Interpreter & Scripting with Python can give us a better approach for interacting with Operating Systems as well as integrating with them. These methods are especially useful in various technologies from Cyber Security to Infrastructure Management.

 

Here, we use Python Interpreter in Linux Environment which will help us in understanding Python as well as a Linux environment which is the backend of most of today’s technologies.

 

Let's start our journey which is a complete pool of Fun…..


 

Lab Required :

 

  1. VMware or VirtualBox installed

  2. KALI Linux Virtual Machine 

  3. KALi Linux with configured Repository

  4. Install Python in KALI Linux

            

Alternate Lab :

 

  1. WSL 2 (Windows Subsystem Linux) enabled

  2. Download KALI Linux from Microsoft App Store

  3. Configure Repository in WSL2 KALI

  4. Install Python in WSL2 KALI

 

 

Hands-On with Python :

 

1. How do commands run in Linux?

 

So let’s investigate the source of operation.


This image demonstrate the Source Location of Commands in Linux OS.

Source Location of Commands


 

Usually, Commands operate from /usr/bin or /usr/sbin directory in Linux. It means we have to create our own commands in these directories.


This image demonstrates the Creation of File at specific location in Linux OS.

Creation of File at Specific Location


Here, we created our file where we will put in our code to do some operation. 


This image demonstrates the Permissions required for command file.

Permission required for Command File


If we try to operate the command, we get an error: 

bash: /usr/bin/moon: Permission denied 

 

What does this error mean?

 

It means /usr/bin has a moon file but it does not have permission to execute. So, we have to make it executable. 


This image demonstrates to permit a file to be executable.

Permit a file to be Executable


This time there is no error in the execution of the moon file.


 

2. How will Code behave with Interpreter & Command File


This image demonstrates the Python Interpreter Working.

Python Interpreter Working


As you can see, I just print my name using Python Code and it’s working well. Here, you got the behavior of the Interpreter what we have defined in Interpreted Programming Language.

 

Now, Put the same code in the command file & Save it.


This image demonstrates the Editing a file with Python Code in Linux OS.

Editing a file with Python Code


Now, try to execute the moon file.

 

This image demonstrates the Error at the time of Execution of command file.

Error due to execution of Command FIle


 

Here, you got an error :

/usr/bin/moon: line 1: syntax error near unexpected token `"Priyanshu Gupta"'

/usr/bin/moon: line 1: `print("Priyanshu Gupta")'

 

Even you have put the same code as you write in Python Interpreter. Because this file is a Plain Text File, to execute it we need a program that can understand & lead this program.


This image demonstrates the Alternative way of execution of any Command.

Alternative way of execution of Command


Here, just focus we execute the Python 3 interpreter by executing the source of location, which leads to the Python 3 Interpreter. We will follow the same to lead our plain text file. Because Script will run line by line where First line execution for Python Interpreter then we move ahead to write the Code.


This image demonstrates the Interpreted characteristic of Scripts & Python 3.

Interpreted Characteristic of Script & Python 


This is the syntax we need to follow when calling a command to lead the code. Like this, write your code & Save it.


This image demonstrates the final working of commands in both way.

Final Execution of our Command in both way


This is how we developed our Own Command which is executable in both ways.

 

Conclusion

 

Python 3 has been integrated with Linux OS which gives us the basic idea of the functionality of commands. Linux is an open-source environment that is used by most companies in almost every field from development to management of IT Infrastructures.

 

Here, we integrate Linux & Python to work with both Linux as well as Python. We also determine the Interpreted behavior of Python which is very useful in the development of scripts. This is also used to create our own software with Terminal User Interface.

 

This type of development environment is very useful in the domain of Cyber Security & Networking. Especially where tasks are in an order of Priority. This setup also gives us free hands to work in the integration of multiple technologies.

 

In this series, we will learn to use Python3 for creating Scripts.

 

“You are not Script Kiddies, You have your Own way of Defending & Attacking ”

 

Hoping you enjoyed going through this blog. 

Latest Comments