What Is Python
What Is Python
MACHINE LANGUAGE
Comp – Collection of electronic circuits
Binary no system for inputs and interpreting outputs
Instruction to microprocessor – Series of 0s and 1s
Decimal can be converted to binary
Instruction Formats
Complete set of instruction for CPU : machine language code
Pros:
No translation
Execution is quick
Cons:
Difficult to write and locate bugs
For same process, instn code for processors made by diff
manufacturers are diff.
Therefore, program written in one machine
lang for one type of CPU will work on comp
having same type of CPU.
No portability
Difficult conversion
ASSEMBLY LANGUAGE
Instruction code are more user friendly
Instructions include short words called
mnemonics
MOV, SUB, ADD
Needs ASSEMBLER
Lack of portability
Difficult to learn
Laborious
Difficult to debug
HIGH LEVEL LANGUAGE
Human friendly
Consists of words : Keywords and other text
Easily understandable
Appropriate words are chosen.
Words : A set of comp instns
Reduces lines of code for programmer
Compilers or Interpreters are req
DIFFERENT GENERATIONS
Machine level lang : 1st generation lang
Assembly level lang : 2nd generation lang
High level lang : 3rd generation lang
With dev of multicore processors lang can
carry out parallel prog, concurrent prog : 4th
generation lang
BYTECODE V/S MACHINE CODE
PYTHON
Popular programming lang
Invented by : Guido van Rossum
Released in 1991 at CWI (Centrum Wiskunde &
Informatica) Netherland.
General purpose lang : can be used in any domain
High level language
Dynamic programming language
Procedural prog lang : Organizing code into
procedures or functions that can be called to
perform specific tasks. Code is organized around
procedures that manipulate data, and the flow of
execution is controlled using control structures
Object oriented programming lang : you can
define classes to create objects that
represent real-world entities and define their
attributes (data) and methods (functions).
Python supports OOP principles such as
encapsulation, inheritance, and
polymorphism.
WHY PYTHON?
Simple and easy to learn
Platform Independent : can run in windows,
linux, mac os etc
Free and open source
Interpreted : code is executed line by line by
an interpreter at runtime.
The Python interpreter compiles the source
code into bytecode at runtime. It is different
from traditional compilation where source
code is compiled into m/c code before
execution
Portable
Rich library support : need not write code
from scratch
Libraries related to math, data science , m/c
learning etc are available.
Embedded and extensible
Robust : error handling, proper memory
management
APPLICATIONS OF PYTHON
Python can be used on a server to create
web applications.
Python can connect to database systems. It
can also read and modify files.
Python can be used to handle big data and
perform complex mathematics.
Python can be used for rapid prototyping, or
for production-ready software
development.
CONTD…
Python works on different platforms
(Windows, Mac, Linux, Raspberry Pi, etc).
Python has a simple syntax similar to the
English language.
Python has syntax that allows developers to
write programs with fewer lines than some
other programming languages.
Designed for readability, and has some similarities
to the English language with influence from
COMPARISON OF PYTHON WITH OTHER PROGRAMMING LANGUAGES
mathematics.
Syntax errors
Runtime errors
SYNTAX ERROR
when the code you've written doesn't follow the
rules and structure of the programming language
you're using.
Syntax errors are like grammatical errors in English.
For example:
prin("Hello World")
The Python interpreter generates the following
syntax error as it did not find a name prin (as the
correct method name is print).
RUNTIME ERROR
Occur due to incorrect algorithm/logic or
wrong operations like dividing by zero during
the program execution.
EXAMPLE OF RUNTIME ERROR
Write a Program to Print:-
Python is Easy
Solution:-
print(“Python is Easy”)
Interesting ways to use
Print functions
1ST: WITH COMMA AS A
SEPARATOR
2ND: WITH SPACE AS A
SEPARATOR
3RD: WITH REPEAT CHARACTER
We can print a string n times by using repeat
character (*) as shown below:
EXAMPLE:
VARIABLES AND ASSIGNMENT
Variable is reserved memory location used to
store values.
For example: age = 21
For example: city = “Tokyo”