0% found this document useful (0 votes)
4 views32 pages

Python Virtual Machine Overview

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views32 pages

Python Virtual Machine Overview

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

NATIONAL

[Unit INSTITUTE
1: Introduction
Course OF ELECTRONICS
to Web Design]
: Basic Python AND
Course: INFORMATION
NIELIT TECHNOLOGY
‘O’ Level (IT)
Day2 Sumit
: Python VirtualComplex,
Machine A-1/9, Vibhuti Khand,
Module: Gomti
M2-R5: Nagar,
Web Lucknow,
Designing & Publishing
1

File and Printer sharing in Windows NT


Environment

Basic Python
Day2
[Unit 1: Introduction
Course
Course : Basic
: Basic to Web Design]
Python
Python Course: NIELIT ‘O’ Level (IT)
Day2 : Python
Day2 : Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
2 Index
 Internal working of Python
 When we run a Python program, two steps happen,
 Python Installation Steps
 Execution of Python Program: You Can execute python progr...
 To Save Program in File
 How to use comments in Python
 Example of multiline comment
 Flow Chart Symbol
 Example
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
3 Internal working of Python
 Python is an object oriented programming language like Java. Python is called an
interpreted language.
 Python uses code modules that are interchangeable instead of a single long list of
instructions that was standard for functional programming languages.
 The standard implementation of python is called “cpython”. It is the default and
widely used implementation of the Python.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
4
 Python doesn’t convert its code into machine code, something that
hardware can understand.
 It actually converts it into something called byte code. So within python,
compilation happens, but it’s just not into a machine language.
 It is into byte code and this byte code can’t be understood by CPU. So we
need actually an interpreter called the python virtual machine.
 The python virtual machine executes the byte codes.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
5
 PVM is nothing but a software/interpreter that converts the byte code to
machine code for given operating system.
 PVM is also called Python Interpreter and this is the reason Python is
called an Interpreted language.
 We can't see the Byte Code of the program because this happens
internally in memory.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
6
 We all know that a computer only understands machine language and
every programming language converts its code to machine language. This
is done by a compiler of that language. The Python compiler also does
the same thing but in a slightly different manner.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
7 When we run a Python program, two steps happen,
The code gets converted to another representation called ‘Byte Code’
‘Byte Code’ gets converted to Machine Code (which is understandable by the computer)
The second step is being done by PVM or Python Virtual Memory. So PVM is nothing but a
software/interpreter that converts the byte code to machine code for given operating system.
PVM is also called Python Interpreter and this is the reason Python is called an Interpreted
language.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
8
 We can’t see the Byte Code of the program because this happens
internally in memory.
 But if we want to see the byte code of the program execute the below
command:
 D:\> python -m py_complie [Link]
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
9
 Here we are calling the Python compiler with the -m option. -m
represents module and the module name is py_compile. This module
generates the .pyc file for .py file. *.pyc file contains the byte code of the
Python program. One can open and see the byte code representation of the
python program. To convert byte code into machine code/output use:
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
10 Python Installation Steps
 First Open Python Official link [Link]
 Download Python latest Version as per your system configuration like-
 What is Your System OS Like- Windows,

Linux/UNIX, Mac OS X, Other


 32/64 Bit OS

 After Download then put Downloaded File in any drive.


[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
11
 Select the file & right click on mouse Button & Further Click on Run as
Administrator.
 Then Screen Will Be Appeared like this.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
12
 Select the file & right click on mouse Button & Further Click on Run as
Administrator.
 Then Screen Will Be Appeared like this.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
13
 In this diagram first check in the Checkbox Add Python 3.6 to Path then
Click on Install Now
 After click on Install Now Screen Will Appear Like this
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
14
 After installation of this screen will be appear like
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
15
 Then Click on close button your python setup is successfully installed.
 After this for Checking installation click on Start Menu>Python
3.6>IDLE (Python 3.6 64-bit)
 >> This Show python Shell. You can also write program on python shell .
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
ExecutionDay2
Day2 :: Python
Python Virtual
of Python Virtual Machine
Program: Machine Module:
You Can execute M2-R5:
python Web Designing
program by two & Publishing
way
16 using
 Python Shell/Terminal
 To Save Program in File
 1-Using Python Shell/Terminal
 Example:
 >>> x=2
 >>> y=2
 >>> z=x+y
 >>> print(z)
 4
 >>>
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
17 2- To Save Program in File
If you want to save the program then in the above display window screen on
your system Click on menu File>New
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
18
In this write program
Example:
x=2
y=2
z=x+y
print(z)
After writing the program Click on File Menu to save the file with
extension .py
Like- [Link]
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
19 How to use comments in Python
 When working with any programming language, you include comments
in the code to notate your work.
 This details what certain parts of the code are for, and lets other
developers – you included – know what you were up to when you wrote
the code.
 This is a necessary practice, and good developers make heavy use of the
comment system. Without it, things can get real confusing, real fast.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
20 Single-line comments
 Single-line comments are created simply by beginning a line with the hash
(#) character, and they are automatically terminated by the end of line.
 For example:
 #This would be a comment in Python
 OR
 #This would be a also comment
 #This would be a also comment
 #This would be a also comment
 #This would be a also comment
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
21 Multi-line comments
 Comments that span multiple lines – used to explain things in more detail
– are created by adding a delimiter (""") on each end of the comment.
 For example:
 """ This would be a multiline comment in Python that spans several lines
and describes your code, your day, or anything you want it to """
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
22 Example of multiline comment
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
23 Algorithm
 An algorithm is a set of well-defined instructions in sequence to solve a problem. A
programming algorithm describes the exact steps needed for the computer to solve
a problem or reach a goal. An algorithm in programming will have several steps as
follows –
 Problem definition – What is to be done?
 Data collection – What do we have to solve the problem? Or inputs.
 Data processing – Understanding what we have or transforming them into a usable
form.
 Logical approach – Employing the collected & created data against logic to solve.
 Solution – Present the solution in the way you want in a GUI or a terminal or a
diagram or a chart.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
24 A good algorithm is –
 [Link] – It knows the exact and correct steps to execute.
 [Link] – The input for the current instructions comes only from the
preceding instruction.
 [Link] – The algorithm ends giving the result after the execution of a
finite number of instructions.
 [Link] – The algorithm holds well to set of inputs and not strictly
one input.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
25
 For writing any programs, the following has to be known:
 • Input
 • Tasks to be preformed
 • Output expected
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
26 Example
 Write an algorithm and draw a flowchart to find simple interest
 Algorithm:
 Step 1: Start
 Step 2: Declare variables amount, rate, time and si.
 Step 3: Read amount, rate and time.
 Step 4: Calculate simple interest as
si=(amount*rate*time)/100
 Step 5: Print si
 Step 6: Stop
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
27 Flow Chart:
 Flowchart is a graphical representation of an algorithm. Programmers
often use it as a program-planning tool to solve a problem. It makes use of
symbols which are connected among them to indicate the flow of
information and processing. The process of drawing a flowchart for an
algorithm is known as “flowcharting”.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
28 Flow Chart Symbol
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
29
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
30 Example
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
31 Assignment:
 Write an algorithm for Adding Two Number and Make Flow Chart
 Create a Flow chart to calculate Area of Circle.
 Visit the Python official website and understand various version of Python.
 [Link]
 Install Python Version according to your PC Configuration.
 Write a program to display message “How are You” to Check Your software is work
or not.
[Unit 1: Introduction
Course
Course :: Basic to Web Design]
Basic Python
Python Course: NIELIT ‘O’ Level (IT)
Day2
Day2 :: Python
Python Virtual
Virtual Machine
Machine Module: M2-R5: Web Designing & Publishing
32

Thank You

You might also like