Python Programming Unit - I: History of Python
Python Programming Unit - I: History of Python
PYTHON PROGRAMMING
UNIT – I:
Introduction:
History of Python :
The History of Python Starts with ABC. ABC (All Basic Codes) is a General-Purpose Programming Language
Developed in the Netherlands. The greatest achievement of ABC was to influence the design of python
what about the name "Python": Most people think about snakes, and even the logo depicts two snakes, but the
origin of the name has its root in British comic. Guido Van Rossum is a big fan of python’s flying circus
Python is now maintained by a core development team at the institute, although Guido van Rossum still holds a
vital role in directing its progress.
Page 2
Python is easy to learn and use. It is developer-friendly and high level programming language.
Python is very easy to code. Compared to other popular languages like Java and C++, it is easier to
code in Python. Anyone can learn python syntax
Mastering Python requires learning about all its advanced concepts and packages and modules. That
takes time.
3. high-level Language:
When you write programs in Python, you never need to bother about the low-level details such as
managing the memory used by your program, we don’t need to remember the system architecture. It
looks more like a readable , human language.
4. Portable:
Let’s assume you’ve written a Python code for your Windows machine. Now, if you want to run it on
a Mac, you don’t need to make changes to it for the same. In other words, you can take one code and
run it on any machine, there is no need to write different code for different machines. This makes
Python a portable language.
5. Interpreted:
If you’re any familiar with languages like C++ or Java, you must first compile it, and then run it. But
in Python, there is no need to compile it. Internally, its source code is converted into an immediate
form called byte code. So, all you need to do is to run your Python code without worrying about
linking to libraries.
By interpreted, mean that the source code is executed line by line, and not all at once. Because of
this, it is easier to debug your code.
Page 3
6. Object-Oriented:
A programming language that can model the real world is said to be object-oriented. It focuses on
objects, and combines data and functions.
Python supports procedure-oriented programming as well as object-oriented programming. In
procedure-oriented languages, the program is built around procedures or functions which are nothing
but reusable pieces of programs. In object-oriented languages, the program is built around objects
which combine data and functionality.
7. Extensible:
you can write some of your Python code in other languages like c or C++. If you need a critical piece
of code to run very fast or want to have some piece of algorithm not to be open, you can code that
part of your program in C or C++ and then use them from your Python program.
8. Embeddable:
we can put code in other languages in our Python source code. However, it is also possible to put our
Python source code in a different language like C/C++.
Python is dynamically-typed. This means that the type for a value is decided at runtime, not in
advance. This is why we don’t need to specify the type of data while declaring it.
11. GUI Programming: (Graphical user interface) You can use Tk to create basic GUIs.
12. Important: Python has been an important part of Google since the beginning and remains
so as the system grows & evolves , Today dozens of Google engineers use Python Python
may become popular for the Internet , as new platforms such as Raspberry Pi are based
on it
Page 4
Python provides Tk GUI library to develop user interface in python based application. Python has
simple syntax, modular architecture, rich text processing tools and the ability to work on multiple
operating systems which make it a desirable choice for developing desktop-based applications. There
are various GUI toolkits like wxPython, PyQt or PyGtk available which help developers create
highly functional Graphical User Interface (GUI). The Kivy is popular for writing multi touch
applications.
8) Network Programming :
Python plays an essential role in network programming. The standard library of Python has full
support for network protocols, encoding and decoding of data and other networking concepts
and it is simpler to write network programs in Python than that of C++.
There are two levels of network service access in Python. These are:
Low-Level Access
High-Level Access
In the first case, programmers can use and access the basic socket support for the operating
system using Python's libraries, and programmers can implement both connection-less and
connection-oriented protocols for programming.
Sockets are the endpoints of a bidirectional communications channel.
9) Database Access :
This is one of the hottest Python Applications. With Python, you have:
Custom and ODBC interfaces to MySQL, Oracle, PostgreSQL, MS SQL Server, and others.
These are freely available for download.
Object databases like Durus and ZODB
Python is often an integral part of Linux distributions. For instance, Ubuntu’s Ubiquity Installer,
and Fedora’s and Red Hat Enterprise Linux’s Anaconda Installer are written in Python
11) Prototyping :
Besides being quick and easy to learn, Python also has the open source advantage of being free
with the support of a large community. This makes it the preferred choice for prototype
development. Further, the agility, extensibility and scalability and ease of refactoring code
associated with Python allow faster development from initial prototype.
Page 7
Python has been used to make 2D imaging software such as Inkscape, GIMP, Paint Shop Pro
and Scribus. Further, 3D animation packages, like Blender, 3ds Max
A program written in a REPL environment is executed piecewise. The term is most usually used to
interactive environment. Common examples include command line shells
Launching IDLE:
Clicking on the IDLE selection will launch IDLE and display the Python Shell window.
Page 8
This is the main window to IDLE, and what we see right now is called the "Interpreter" (or "shell")
window. The Interpreter allows us to enter commands directly into Python, and as soon as we enter
in a command, Python will execute it and display its result.
'>>>' signs act as a prompt for us: Python is ready to read in a new command by giving us that visual
cue. Also, we notice that as we enter in commands, Python will give us its output immediately.
we can't directly save what's on the interpreter window, because it will include both our commands
and the system's responses. let's start with opening up a new window.
Let's save the file now. The Save command is located under the File menu:
Page 10
saved the program and run the If we look at the menus on our program window
Output:
Page 11
Variables plays a very important role in most programming languages, and python is no exception.
Variables are nothing but reserved memory locations to store values.
This means that when you create a variable you reserve some space in memory.
ThisInmeans
Python, we don't need to specify the type of variable because Python is dynamically-typed.
that the type for a value is decided at runtime, not in advance. This is why we don’t
need to specify the type of data while declaring it.
replaced
Non technically, you can suppose variable as a bag to store books in it and those books can be
at anytime.
underscore.
Variable names can be a group of both letters and digits, but they have to begin with a letter or an
Variable Names:
A variable can have a short name (like x and y) or a more descriptive name
(age, MIC, total_volume, tv9, _srikanth).
Output:
Output:
Output:
Output:
Page 13
functionKeywords are the reserved words in Python. We cannot use a keyword as variable name,
name or any other identifier.
They are used to define the syntax and structure of the Python language.
All keywords in Python are case sensitive. except True, False and None So, you must be careful
while using them in your code.
There are 33 keywords in Python 3.3. This number can vary slightly in upcoming
versions
toshown
get hold the up-to-date list, you can open Python shell and run the following commands as
in the below snippet.
and Logical operator to test whether two things are <conditional expression> and
both True. <conditional expression>
x>2 and x<10
continue Skip balance of loop and begin a new iteration. for i in range(10):
if i%2 ==0:
continue
for Create a loop which iterates through elements of for <dummy variable name> in
a list (or other iterable). <sequence>:
for i in range(10):
from Import specific functions from a module without from <module name> import <name
importing the whole module. of function or object>
from random import randint
else
print(“x is not greater than 3, nor is
it 1 one or 2”)
import Use code defined in another file without retyping import <name of module>
it. import random
pass Placeholder keyword. Does nothing but stop for i in range (10):
Python complaining that a code block is empty. pass
while Execute a code block while the associated while <conditional expression>:
condition is True. while True:
pass
with Get Python to manage a resource (like a file) for with open(<name of file>,<file
you. mode>) as <object name>:
Real world programs need to be interactive. That means you need to take some sort of input or
information from the user and work on that input.
We canForachieve
example, you would want to take input from the user and then print some results back.
this using the input()function and print() function respectively
We must always remember that the input function takes user’s input as a string. So whether your
input a number or a string it is treated as a string only.
Example:1
x = input()
print("Hello, " + x)
srikanth
Hello, srikanth
Example:2
output:
INDENTATIONS
White spaces at the beginning of the line is called indentation. The whitespaces or indentations
are very important in python
In most programming languages, indentations has no effect on programming logic. It is
used to align statements to make the code readable.
In python indentation is used to associate and group statements
Example of indentation
The level of indentation groups statements to form a block of statements this means that statements
in a block must have the same indentation level. python very strictly checks the indentation level and
gives an error if indentation is not correct.
Page 18
NOTE: the ^ is a symbol that indicates where error has occurred in the program
Example: