Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Introduction_to_Programming_Python__8_11 (3)

This document introduces Python as an interpreter-based, object-oriented programming language that is widely used for various applications, including web development and data analysis. It outlines the features of Python, such as its simplicity, portability, and extensive libraries, and provides guidance on downloading, installing, and using Python through IDLE. Additionally, it explains how to write, save, and execute Python programs, as well as how to use Python as a calculator.

Uploaded by

Satyadev Prasad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Introduction_to_Programming_Python__8_11 (3)

This document introduces Python as an interpreter-based, object-oriented programming language that is widely used for various applications, including web development and data analysis. It outlines the features of Python, such as its simplicity, portability, and extensive libraries, and provides guidance on downloading, installing, and using Python through IDLE. Additionally, it explains how to write, save, and execute Python programs, as well as how to use Python as a calculator.

Uploaded by

Satyadev Prasad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction to Programming Python

Chapter 8
Introduction to Python
A programming language is designed to help process certain kinds of data to
provide useful output known as information. The task of processing data is done
by executing a sequence of instructions called a program. These instructions
are written using certain symbols, codes, and words according to some rules
known as syntax or grammar. Like any other programming language, Python
has its vocabulary and grammar.
Python is an interpreter-based, object-oriented programming language. It is a
general-purpose, high-level language with interactive features. It supports the
development of wide range of applications from simple text processing to web
browsers to games. Python is the open source software and was founded by
Guido Van Rossum in 1991. It is named after Python’s Flying Circus, a
comedy program.
Python is the most widely used programming language. Some of the important
places where Python is used are:
 Web Programming Development
 GUI Application Development
 Used for Data Analysis
 Software Development
 Scientific Applications

Features of Python Programming


 Python is a simple yet powerful language. The popularity of Python is
increasing every day because of the following features:
 Easy: It is easy to learn and understand.
 Syntax: The syntax or grammar of Python is simpler, hence, makes it
easier to learn and understand.
 Free: Python is an open-source language available to download from the
internet for free.
 Portable: Programs are written in Python, can run almost in every
known platform, such as Windows, Linux, or Macintosh.
 Libraries and Tools: Programming in Python is easier because the
libraries and supporting tools make even a composite task easy.
 Debugging: It is an interpreted language that executes code line by line
at a time. Hence, makes debugging easier.
 Extensibility: It is an extensible language, and hence, can be extended
to other languages.
 Dynamic Memory Allocation: When an object is created in Python,
memory is dynamically allocated to it. The memory is taken back when it
is no longer being used.

Getting Started in Python


Downloading and Installation of Python
The first step to install Python is to download the latest version of the
installation package from the link\URL given below:
https://www.python.org/downloads/

Click on the
Download
Python
button with
the latest
version.

In this chapter, we are using version 3.9.5.


After downloading the Python setup, run it to install.
Working in Python
Once Python is installed, we will use IDLE to write and run Python programs.
IDLE is an Integrated Development Learning Environment. It is the most
popular graphics-based development environment that allows us to create, edit,
run, and debug Python programs.

To open IDLE, follow the steps


given below:
1. Search for Python in 2
Search Box.

2. Choose the IDLE option


from the list.

1
Python 3.9.5 shell window opens up when we launch IDLE. It is an interactive
window where we can type Python code and view the output in the same
window.

Menu bar

Command
Prompt

We can type here

Python provides two different ways to work with:

Interactive mode (Python Shell Window)


In the Python shell window, we write a code that executes one line at a time. In
Shell window, >>> sign appears, here we can write our code and press enter.
To exit from the IDLE window, there are various options:
Press Ctrl + D from the keyboard
or Click File  Exit
or Click on the cross ( x ) button on the Title bar.
Script Mode (Python Editor’s Window)
Python gives output immediately as you enter code and press Enter key but if
you want to see all the output after completion of code, then you can use Python
script mode.
To open Python Editor’s Window, follow the steps given below:
1. Open the Python Shell Window
2. Click on the File menu option on the menu bar.
3. From the drop-down menu, click on the New File option.

1
2

Python Editor’s Window opens.


Starting First Program
We can display our content in two different ways in Python.
Without using print() function
Step 1: Open Python shell window.
Step 2: In front of the command prompt, type “Hello Class” and press enter.
Step 3: The output displays in the next line in the same Python shell window.

Using print() function – We use the print() function to display the content on
the screen. The content is written within the parentheses.
Step 1: Open the Python shell window.
Step 2: In front of the command prompt, type print(“Hello Class”) and press
Enter key.
Do not forget to include the double quotes (“ ”).

Step 3: The output displays in the next line in the same Python shell window.
Using Python as Calculator
Python command prompt also acts as a calculator. We can use arithmetic
operators like +, -, *, and / to compute any expression.
To perform calculations, follow the steps given below:
1. Type 10 + 10 in front of the command prompt and press Enter key in the
keyboard.
20 is displayed in the next line in the same Python shell window.
2. Now type 100 – 10*2, and press Enter in the keyboard.

80 is displayed in the next line.


3. Type 60/5 and press Enter key in the keyboard. 12.0 is displayed in the
next line.
Writing Program in Python Editor’s Window
Python shell does not allow us to save our commands written on the command
prompt. For saving and reusing our programs, we write our code in Python
Editor’s window. It allows us to write multi-line code that we can save, open,
run, edit and debug easily.
For writing a code in Python’s Editor window, follow the steps given below:
1. Open Python’s Editor window.
2. When we open a new file, it is named ‘untitled’ by default.
3. Now, write our first program in the script window.

Saving a Program
After finishing our
coding, we can save our 1
program. We do not need
to rewrite the same
program every time we
want to use it. 2
For saving a program,
we need to follow the
steps given below:
Step 1: Click on the File
menu.
Step 2: From the drop-down menu, choose Save.
The Save as dialog box appears.

By default, the file will be


saved in the Python folder
in C: drive, but you can
change the location.
Step 3: Type the name of
file in the File name
textbox.
3
The file extension of
Python is .py.
4
Step 4: Click on Save.
The new filename will
appear on the Title bar.

Executing a Program
Once the program is saved, we can execute or run it. For executing a program,
we need to follow the steps given
1
below:
1. Click on the Run menu 2
on the menu bar.
2. From the drop-down,
click on the Run Module
option.

Or
Press the F5 function
key in the keyboard.
Short Key
The output will be displayed in the Python shell window.
To execute a program: F5
Opening a Program
To view the earlier-saved 2
program, we need to 3
follow the given steps:
Step 1: Open Editor’s
window.
Step 2: Click on the File
menu.
Step 3: Choose the Open
option from the drop-
down.
An Open dialog box appears.
Step 4: Select the program to be opened or type name in the File name box.
Step 5: Click on the Open button.
4

The program code will be displayed in the Python Editor’s window.

Exiting Python
After we are done writing our coding, we can close Python IDLE. To exit
from Python IDLE,
1
we need to follow the
steps given below:
Step 1: Click on the File
menu on the menu bar.
Step 2: From the drop-
down, choose the Exit
option. 2
The Exit option will
close all the open files
and windows, and exit the program. But, if we click on the Close option, it will
close the active file.

Or
Step 1: Type exit() in front of the command prompt.
A confirmation message is displayed.
Step 3: Click OK for exiting Python.

You might also like