Getting started with Python programming

Objectives

(1) Python an introduction

(2) Installation & set up Python in Command Prompt

(3) Start Python programming using Command Prompt or IDLE

(4) Create & run a Python file using Command Prompt or IDLE

(5) Which is better Command Prompt or IDLE for Python programming?  


Python an Introduction

Python is a High-Level, general purpose & Object-Oriented programming language. Python is simple, versatile and have extensive range of applications. These applications may include automation, web development, data analysis, artificial intelligence & machine learning, and more.

High-level language means it allows human to write computer programs to interact with a computer system without having specific knowledge of the processor or hardware.

Object-oriented programming (OOP) is a programming paradigm based on the concept of objects which contains data in the form of fields (known as attributes or properties) and code in the form of procedures (known as methods).

Python is also called an scripting language. Scripting languages are usually interpreted rather than compiled, meaning they are executed directly by an interpreter line-by-line rather than being converted into machine code first. This allows for quick testing and iteration. It is used to automate tasks such as file manipulation, system administration, and data processing.


Installation & set up Python in Command Prompt

Step-1: For installation of latest version of Python on Windows operating system, visit official page of Python 'https://www.python.org/downloads/'. Now download the Windows installer .exe file.




Step-2: Run the Installer

Open .exe file 'python-3.12.5-amd64.exe' by double clicking on it to launch the Python installer. Choose option 'Install Now' and subsequently follow the instructions.

Step-3: Verify Python Installation

After installation of Python, check that installation of python was successful by using Command Prompt or Integrated Development Environment(IDLE).

Open the Windows search bar and search for “idle”. Without opening the app, click on “Open file location”.




Step-4: Right-click on “IDLE” and click on “open file location”.

After opening the file location, copy the path.




Step-5: Search 'environment variables' in Windows search bar then double click on 'Edit environment variables for your account'.


In System Properties menu click on 'Environment Variables'.




In System Variables double-click on 'path'.




In 'Edit environment variable', click on 'New' and paste the copied file location and then click OK.




Step-6: Check Python set up successful or not in Command Prompt.

Press 'Windows+R' type CMD then click OK.

Command Prompt will open, now type python then enter.




The result below will show python version installed.




That means Python installation is successful & Command Prompt is ready to run Python programs. 

The same can be done with IDLE.

Search 'idle' in Windows Search Bar. Click on 'Open' then on top of IDLE window will show installed Python version. 




Start Python programming using Command Prompt or IDLE  

Step-7: Run first program

Type print("Hello, World!") in CMD then enter.




Result will show "Hello, World!".




It is the first python program using print function print() which was run on CMD.

After job is finished, required to quit the Python Command Line Interface use the command exit().

The above program can also be run using IDLE Shell. 

Open IDLE shell.



In IDLE Shell, type print("Hello, World!"), hit Enter the output is Hello, World! as below:




Create & run a Python File using Command Prompt or IDLE

To run a program, first create a file in notepad, write code & save the file in '.py' format. 

In case of CMD, first copy the destination path where the file is to save.

Open command prompt then use change directory command 'cd' with destination path as 'cd C:\Users\aaate\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.12' then Enter.




After using 'cd' command, CMD has been change it's working directory to desired destination path where file is to save. Now use the command 'notepad code14.py' then Enter to open existing file or create a new one. 




If the file name code14.py is already present it will open the file otherwise it will ask to create a new file with name code14.py click on 'Yes' in a new window as below:





A new file with name 'code14.py' has been created. Now write the code for example write script print("Hello, World!") then 'Ctrl+S' to save.




In future to run above program, open command prompt, change directory using command 'cd' with destination path where file 'code14.py' was saved, now use command 'python code14.py' then Enter to show the output as below:




In case using IDLE, Go to File, click New File.




A new text editor window will open, write script as print("Hello, World!").




Go to file then SAVE.




Write file name 'code14' then SAVE. The file will be saved in .py format.

To reuse the above program go to File, click Open, select file name 'code14', click Open.




A new window will be opened that means file code14.py has been opened.

Now go to Run into file window, click Run Module, then result will show Hello, World! into IDLE Shell window.




Which is better Command Prompt or IDLE for Python programming? 

The choice between Command Prompt and IDLE for Python programming depends on the needs and preferences.

Command Prompt provides flexibility to run Python scripts from any directory and it is versatile suitable for running scripts & automating tasks.

But Command Prompt have no Integrated Development Environment (IDE) features lacks syntax highlighting, debugging tools like as in an IDE.

On other hand IDLE (Integrated Development and Learning Environment) is Beginner-Friendly comes with Python and provides an easy-to-use interface, have integrated built-in features like syntax highlighting, debugger, which makes it easier to write and debug code and have interactive shell allows for immediate execution of Python commands.

Use Command Prompt if need to manage files, run scripts, and use Python alongside other command-line tools and working on larger projects.

Use IDLE if just starting with Python and needed an environment that provides some basic coding assistance, for small scripts or learning, where to get benefit from the integrated features like the interactive shell and simple debugging.

Beginners or those working on small, quick tasks may find IDLE more helpful due to its ease of use and integrated features.

More experienced developers or those working on larger projects may prefer the flexibility of the Command Prompt, often in combination with a more powerful IDE like VSCode, PyCharm, or others.

Comments

Popular posts from this blog

OWASP Top 10

TCP/IP Model

AAA