Python Programming
Python programming language
was invented
by
Guido Van Rossum
(early 1990)
❏ Python is a high-level, general-purpose programming language for solving problems on modern computer
systems.
❏ The language and many supporting tools are free, and Python programs can run on any operating system.
❏ It has fewer syntactic constructions than other languages.
❏ Python is an interpreted language, not a compiled language. That means that unlike applications written in
languages such as C, COBOL or Assembler, code written in Python has to run through a process of
interpretation by the computer.
❏ Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and
classes. Other programming languages often use curly-brackets for this purpose.
Features
❏ Python is an interpreted language.
❏ Easy to learn:- It has few keywords, simple structure and clearly defined syntax.
❏ Easy to read:- It is clearly defined.
❏ Easy to maintain:- It is fairly easy to maintain.
❏ Portable:- It can run wide variety of hardware platforms and has the same interface on all
performs.
❏ Databases:- It provides interfaces to all major commercial databases.
❏ Extendable:- Adding of low level modules to python is possible.
❏ Scalable:- It provides a better structure and support for larger programs.
❏ It supports functional and structured programming.
❏ It can be used as scripting language and can be compiled to byte code to form larger
applications.
❏ It supports automatic garbage collection.
❏ It can be easily integrated with other programming languages like c,c++,java
Running code in interactive shell
❏ You can run simple python expression & statements in an interactive programming
environment called Shell.
❏ Easiest way to open python shell is to launch the idle.
❏ A shell contain an opening message followed by the special symbol >>>, called a
shell prompt.
❏ The cursor at the prompt waits for the user to enter python command.
>>>3+4
>>>”Hello”
‘Hello’
>>>”Hi”+”everyone”
‘Hi everyone’
>>>print(‘Hi’)
Hi
❏ To quit the shell either select window close box or press ctrl+D
Input, Processing, and Output
❏ In python shell, inputs are python expressions or statements.
❏ Processing evaluates these items.
❏ Outputs:- results displayed in the shell using ‘print’ function.
print(<expression>)
>>>print(“Hello”)
Hello
❏ Print function displays a string without the quotation marks.
❏ It always ends its output with a newline.
❏ To begin the next output on the same line, you can place end=“ ”, which says end line with
an empty string.
print(<expr>, end=“ ”)
❏ To make the program ask the user for input, you can use ‘input’ function. This function
causes the program to stop & wait for the user to enter a value from the keyboard
❏ To make the program ask the user for input, you can use ‘input’ function. This function
causes the program to stop & wait for the user to enter a value from the keyboard.
❏ When user presses the enter key, function accepts the input value & makes it available to
the program.
>>>name=input(“Enter your name:”)
Enter your name : Sweety
>>>name
‘Sweety’
❏ A variable identifier or variable is a value when a just a name for a value. When a variable
receives its value in an input statement, the variable refers to this value.
<variable>=input(<string>)
❏ The input function always accepts a string value from the user.
❏ So to represent numbers, programmer must convert them from string to numeric types.
❏ 2 type conversion functions- int, float
>>>a=int(input(“Enter 1st no:”))
Enter 1st no: 2
>>>b=float(input(“Enter 2nd no:”))
Enter 2nd no:4.6
Editing, Saving & Running a script
❏ We compose, edit & save longer, more complex programs in files.
❏ We can run these scripts either within IDLE or from OS’s command prompt.
How Python works?
❏ The interpreter reads a python expression or statement, also called the source code and
verifies that it is well formed.
❏ The interpreter rejects any sentence that does not adhere to the grammar rules, or syntax of
a language. As soon as the interpreter encounters an error, it halts translation with an error
message.
❏ At a python expression is well formed the interpreter then translates it an equivalent form in
a low level language called bytecode.
❏ This byte code is next send to another software component called Python Virtual Machine
(PVM), where it is executed. If another error occurs during this step, execution also halts
with an error message.
Detecting and correcting syntax errors
❏ Python interpreter will nearly always detect typographical errors made by the
programmer. Such errors are called syntax errors.
❏ The term syntax refers to the rules for forming sentences in a language.
❏ When python encounters a syntax error in a python, it halts execution with an
error message.
❏ Indentation is significant in python code.
❏ There are fewer types of syntax errors in python.
Software development process
❏ Process of planning and organizing a program.
❏ Several approaches are available: one version is the waterfall model.
Customer Request
Analysis
Design
Implementation
Integration
Maintenance