Book Template
Book Template
Book Template
Learn Python 3
June 2, 2024
1
Table of Contents
List of Programs 3
List of Figures 4
Preface i
1 Introduction 1
1.1 Install Python in Windows 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Install Python in Linux – Ubuntu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Modes of running Python programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Blocks of codes and indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 print() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.6 Documentation of Python standard libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.7 Syllabus covered by this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.8 Syllabus for Engineering Courses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.9 Why Python – finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Numbers 17
3.1 Numerals – int and float types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Summary of operations on int and float data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4 Strings 21
4.1 String variable assignment and other basic operations . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2 Advanced operations on Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5 Operators 23
2
Table of Contents 3
Postface 39
4
List of Figures
5
Preface
Seizing the digital opportunity needs an expertise in an holistic programming tool. Target is to explain how to
build a web based responsive application using open source tools like Postgres, Django and Tailwind CSS. To start
such development, how to program with Python is explained in this book.
Development of web applications using a set of the following open source technologies is explained to the best of
my knowledge. The technologies are:
Server Scripting Python based framework, Django for developing MVT based application
OS Linux internals
This book is more of a write-up notes for my memory, rather than a full blown text Book. Kindly bear with this,
as it needs frequent reference of other text books and the Internet.
i
Chapter 1
Introduction
Python does many things in more efficient way and is becomming more popular. Python was designed by Guido
Van Russom, named after Monty Python series. Python can be downloaded from www.python.org. With a rich
ecosystem of modules and frameworks, effective application development becomes really easy.
• Spyder
Anaconda distribution of Python has many required modules in a single source, and is available at www.anaconda.
com. This book uses any suitable distribution on any OS (Ubuntu 20.04 or Windows 10), and all efforts are made
to explain the concept. Some of the other similar distributions of Python are
1. CPython, this one has a steep learning curve and is for an experienced programmer.
3. ActiveState python.
1
2 Chapter 1. Introduction
2. Search for Python and select Python 3.9, which is current version, and select Get.
3. Once installation is successful, for checking open Windows Power Shell from Start and type python --version .
Python3.x comes pre-built in Ubuntu 20.04 OS. However installing can be done in the following steps in the
terminal2 .
2. python --version for checking the installation. It should say Python 3.9.5
3. sudo apt install python3-pip for installing pip, a nice tool for managing packages and modules dur-
ing development.
4. sudo apt install -y python3-venv for having a virtual environment, an isolated space, for developing
without any clash with various versions of the libraries.
5. sudo apt install -y build-essential libssl-dev libffi-dev python3-dev , additional required li-
braries.
Python scripts (Programs) can be run from REPL Shell interactively or from a scripted file with .py extension.
Larger and complex applications naturally need the later mode.
#!/bin/env python
print("Hello world")
2 Refer https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-programming-environment-on-an-ubuntu-
and many other sources from the Internet
Checking the installed versions of Python and Pip 3
The fig. 1.2 shows the installed version of Python and pip in Ubuntu 20.04, local instance.
The blocks of codes generally included between {} , in C, Java etc. But Python does it differently, by indenting
the codes, levels of indentation is grouped under those respective blocks, which is called a Suite in Python.
Indentation is generally 4 spaces.
All statements with same indentation belong to one block, this block ends with a statement with lesser indentation
or EOF.
a = 15
if a % 2 == 0:
# This Suite of code is executed if True
print(a, " is even")
else:
# This Suite of code is executed if False
print(a, " is odd")
Syllabus
UNIT I
Introduction:Introduction to Python, Program Development Cycle, Input, Processing, and Output, Display-
ing Output with the Print Function, Comments, Variables, Reading Input from the Keyboard, Performing
Calculations, Operators. Type conversions, Expressions, More about Data Output. Data Types, and Ex-
pression:Strings Assignment, and Comment, Numeric Data Types and Character Sets, Usingfunctions and
Modules.Decision Structures and Boolean Logic: if, if-else, if-elif-else Statements, Nested Decision Struc-
tures, Comparing Strings, Logical Operators, Boolean Variables. Repetition Structures: Introduction, while
loop, for loop, Calculatinga Running Total, Input Validation Loops, Nested Loops.
UNIT II
Control Statement:Definite iteration for Loop Formatting Text for output, Selection if and if else Statement
Conditional Iteration The While LoopStrings and Text Files:Accessing Characterand Substring in Strings,
Data Encryption, Strings and Number Systems, String Methods Text Files.
UNIT III
List and Dictionaries:Lists, Defining Simple Functions, DictionariesDesign with Function: Functions as Ab-
straction Mechanisms, Problem Solving with Top Down Design, Design with Recursive Functions, Case
Study Gathering Information from a File System, Managing a Program’s Namespace, Higher Order Func-
tion.Modules: Modules, Standard Modules, Packages.
UNIT IV
File Operations: Reading config files in python, Writing log files in python, Understanding read functions,
read(), readline() and readlines(), Understanding write functions, write() and writelines(), Manipulating
file pointer using seek, Programming usingfile operations Object Oriented Programming:Concept of class,
object and instances, Constructor, class attributes and destructors, Real time use of class in live projects,
Inheritance , overlapping and overloading operators, Adding and retrieving dynamic attributes of classes,
Programming using Oops support Design with Classes:Objects and Classes, Data modeling Examples, Case
Study An ATM, Structuring Classes with Inheritance and Polymorphism
UNIT V
Errors and Exceptions: Syntax Errors, Exceptions, Handling Exceptions, Raising Exceptions, User-defined
Exceptions, Defining Clean-up Actions, Redefined Clean-up Actions.Graphical User Interfaces:The Behav-
1.9. Why Python – finally 9
ior of Terminal Based Programs and GUI -Based, Programs,Coding Simple GUI-Based Programs, Other
Useful GUI Resources.Programming:Introduction to Programming Concepts with Scratch.
Text Books
Reference Books
e-Resources
https://www.tutorialspoint.com/python3/python_tutorial.pdf
Summary 1.1
Summary 1.2
Python is highlevel, open source, interprated and general purpose coding language
which is now becomming the most popular.
1.10 Exercises
1.1 Write a program which prompts for two numbers and prints the product of these two numbers.
A Variable is a memory space with a name, available for storing data while the program is run.
An Object is a blueprint of a bunch of variables along with the methods which execute certain predefined pieces
of tasks using these variables.
a) ID b) Type c) Value
Data are placed in these variables, which is of different types and hence need different treatment, like addition of
numbers is not same as adding two strings. Data are anything that can be processed by program either as input
or as output, including Meta Data, which give the details about the data.
Lists are arrays of any of these objects like [ 5, 'a', [2,"Sea Shell"],'fine tune']
Files are stream objects which can be opened for writing or reading.
Program related objects are Functions, classed and modules which can be defined using keywords like
def, class, lambda, import etc.
The list above may seem to be overwhelming, but they are quite powerful and useful in programming a very
complex application.
Mutable data types can change their values during the runtime, while Immutable ones do not change during the
entire runtime.
Python does many things in a very different way than it is handled by the most popular programming languages.
Defining a data type mutable is one of such special technique in Python, which makes the things very faster and
simpler. Data types like String, Numerals are immutable, which means they won’t change for that instance of the
program execution.
Numerals are immutable? are you sure, int and float are also immutable?, check this during next section.
In Python a variable can be declared and initialise in a single command, in Program 2.1, it is clearly seen that
Python is intelligently assigning the relevant data type to the variable based on the value it is being initialised. It
is also explained how to initialise multiple variables with a same value.
It can also be noticed that a single char is also of a str type of length 1, in Python, there is no special char data
type. Python specifically doesnot restrict the size of the variables that can go into these variables, rather it will be
constrained only by the capability of the machine on which the program is running.
2.4. How to input data while running a Python script 13
#!/bin/env python
a = 25
pi = 3.14159
hello = "Hello World"
The Program 2.2 shows that int and float are immutable. The new assignment of a and b created new objects
and are pointing to new locations as shown in the output.
#!/bin/env python
Python allows user to give input while the programs are run in script mode in two ways
Input() function is helpful in taking the values of any variable from the keyboard. The Program 2.3, shows some
ways to enter data.
14 Chapter 2. Data types, Variables and Operators
#!/bin/env python
This needs a little more understanding on how the variables and values are processed in Python. Arguments
without keywords are passed through commandline as we do in C, identified by *args. Arguments with keywords
are also there in Python which are represented by **kwargs. Here we pass argument with its name(key) and value.
More explanation is available after explaining functions.
2.5 Operators
Operations like addition, subtraction, etc., are defined in Python which are generally operated on one, two or
three variables. The operators available in Python are Project 2.1
Unary + - * /
Binary + - * / % **
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adi-
piscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id,
vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et
netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus
vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est,
iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec
varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit
amet orci dignissim rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam
lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan bibendum,
erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse
ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient mon-
tes, nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque
cursus luctus mauris.
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero.
Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit.
Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas
lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat
magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel
magna. Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam
cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu
massa.
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus tincidunt ultrices. Lorem
ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst. Integer tempus con-
vallis augue. Etiam facilisis. Nunc elementum fermentum wisi. Aenean placerat. Ut imperdiet, enim sed
gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus eget enim. Nunc vitae tortor. Proin
tempus nibh sit amet nisl. Vivamus quis tortor vitae risus porta vehicula.
Fusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibus semper, leo velit ultri-
cies tellus, ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam pellentesque, augue quis sagittis
posuere, turpis lacus congue quam, in hendrerit risus eros eget felis. Maecenas eget erat in sapien mattis
porttitor. Vestibulum porttitor. Nulla facilisi. Sed a turpis eu lacus commodo facilisis. Morbi fringilla,
wisi in dignissim interdum, justo lectus sagittis dui, et vehicula libero dui cursus dui. Mauris tempor
ligula sed lacus. Duis cursus enim ut augue. Cras ac magna. Cras nulla. Nulla egestas. Curabitur a leo.
Quisque egestas wisi eget nunc. Nam feugiat lacus vel est. Curabitur consectetuer.
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu. Aenean faucibus
pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel, nisl. Ut lectus eros, malesuada
sit amet, fermentum eu, sodales cursus, magna. Donec eu purus. Quisque vehicula, urna sed ultricies
auctor, pede lorem egestas dui, et convallis elit erat sed nulla. Donec luctus. Curabitur et nunc. Aliquam
dolor odio, commodo pretium, ultricies non, pharetra in, velit. Integer arcu est, nonummy in, fermentum
faucibus, egestas vel, odio.
Sed commodo posuere pede. Mauris ut est. Ut quis purus. Sed ac odio. Sed vehicula hendrerit sem. Duis
non odio. Morbi ut dui. Sed accumsan risus eget odio. In hac habitasse platea dictumst. Pellentesque non
elit. Fusce sed justo eu urna porta tincidunt. Mauris felis odio, sollicitudin sed, volutpat a, ornare ac, erat.
Morbi quis dolor. Donec pellentesque, erat ac sagittis semper, nunc dui lobortis purus, quis congue purus
metus ultricies tellus. Proin et quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra,
per inceptos hymenaeos. Praesent sapien turpis, fermentum vel, eleifend faucibus, vehicula eu, lacus.
16 Chapter 2. Data types, Variables and Operators
2.6 Exercises
Numbers
Python allows using numbers in integers (int and long), float, complex and bool types.
Python does not need explicit declaration of any data type, depending on the value of the object, it decides the
data type. If a number is stored in a variable it decides whether it is int or float type. However, type casting is
also available for further control on the type of variable.
Summary 3.1
Title of this summary
a = 25
b = 3
a + b = 28 # Addition
a - b = 22 # Subtraction
a * b = 75 # Multiplication
17
18 Chapter 3. Numbers
The operations on float are summarised below, where operation true division of floating point numbers give an
unexpected result, because of the way floating point variables are stored and rounded1 .
Summary 3.2
a = 20.65
b = 3.14
a + b = 23.79 # Addition
a - b = 17.509999999999998 # Subtraction
a * b = 64.841 # Multiplication
1 https://stackoverflow.com/questions/14763722/python-modulo-on-floats
3.2. Summary of operations on int and float data types 19
a = 25 # Is an integer
Strings
String is a builtin data type in Python for handling text and is an immutable object. The following discussion
explains various capabilities of a string.
""" Commenting a
multiline
messsage in a program
as PEP8 does not recommend
any line beyond 80 characters
"""
Initialise mystring = "Hello World" creates a string variable and initialises with ”Hello World”.
Indexing mystring[0] refers to h and mystring[1] refers to e and so on, index starts from 0
to len(mystring)-1
Negative indexing mystring[-1] is the last character - d. Similarly mystring[-2] is l. Guess what is
mystring[-len(mystring)] ?1 . Explanation is depicted in the ??
1 mystring[-len(mystring)] = h , i.e., first character
21
22 Chapter 4. Strings
The Program 4.1 illustrates multiline text handling and errors in index.
#!/usr/bin/env python
print(strmulti)
#Range error
print("String index range error")
print(mystr[25])
4.3 Exercises
4.1 Write a program to prompt user to enter his name and greet him saying hello.
Chapter 5
Operators
Any Operator is defined for a specific operation on operands. Operators can be specified as logical or arithmentic
depending on their specific operation.
Operators can be classified in the following three ways depending on the number of operands.
Unary operators take one operand and some examples are given in the fig. 5.1, further examples are explained
23
24 Chapter 5. Operators
Operators which take two operands for performing assigned operation are Binary operators. The fig. 5.2 explains
some of the Arithmetic binary operators. Relational operators compare two operands and is explained in fig. 5.3.
Summary 5.1
a = 25
b = 3
5.2. Binary operators 25
a + b = 28 # Addition
a - b = 22 # Subtraction
a * b = 75 # Multiplication
a = 25 # Is an integer
Python allows using numbers in integers (int and long), float, complex and bool types.
a = 25 # Is an integer
27
Chapter 7
Summary 7.1
29
30 Chapter 7. Test for gitting
>>>
#!/usr/bin/env python
print(strmulti)
#Range error
print("String index range error")
print(mystr[25])
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adi-
piscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id,
vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et
netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus
vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est,
iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec
varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit
amet orci dignissim rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam
lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan bibendum,
erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse
ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient mon-
tes, nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque
cursus luctus mauris.
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero.
Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit.
Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas
lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat
magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel
magna. Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam
cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu
massa.
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus tincidunt ultrices. Lorem
ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst. Integer tempus con-
vallis augue. Etiam facilisis. Nunc elementum fermentum wisi. Aenean placerat. Ut imperdiet, enim sed
gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus eget enim. Nunc vitae tortor. Proin
tempus nibh sit amet nisl. Vivamus quis tortor vitae risus porta vehicula.
Fusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibus semper, leo velit ultri-
cies tellus, ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam pellentesque, augue quis sagittis
posuere, turpis lacus congue quam, in hendrerit risus eros eget felis. Maecenas eget erat in sapien mattis
porttitor. Vestibulum porttitor. Nulla facilisi. Sed a turpis eu lacus commodo facilisis. Morbi fringilla,
wisi in dignissim interdum, justo lectus sagittis dui, et vehicula libero dui cursus dui. Mauris tempor
ligula sed lacus. Duis cursus enim ut augue. Cras ac magna. Cras nulla. Nulla egestas. Curabitur a leo.
Quisque egestas wisi eget nunc. Nam feugiat lacus vel est. Curabitur consectetuer.
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu. Aenean faucibus
pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel, nisl. Ut lectus eros, malesuada
sit amet, fermentum eu, sodales cursus, magna. Donec eu purus. Quisque vehicula, urna sed ultricies
auctor, pede lorem egestas dui, et convallis elit erat sed nulla. Donec luctus. Curabitur et nunc. Aliquam
dolor odio, commodo pretium, ultricies non, pharetra in, velit. Integer arcu est, nonummy in, fermentum
faucibus, egestas vel, odio.
Sed commodo posuere pede. Mauris ut est. Ut quis purus. Sed ac odio. Sed vehicula hendrerit sem. Duis
non odio. Morbi ut dui. Sed accumsan risus eget odio. In hac habitasse platea dictumst. Pellentesque non
elit. Fusce sed justo eu urna porta tincidunt. Mauris felis odio, sollicitudin sed, volutpat a, ornare ac, erat.
Morbi quis dolor. Donec pellentesque, erat ac sagittis semper, nunc dui lobortis purus, quis congue purus
metus ultricies tellus. Proin et quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra,
per inceptos hymenaeos. Praesent sapien turpis, fermentum vel, eleifend faucibus, vehicula eu, lacus.
32 Chapter 7. Test for gitting
Tip 1
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat
ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus
sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc.
Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu,
pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis
nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non ju-
sto. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed
accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et
nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt
urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique,
libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipi-
scing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat
a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a,
ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla
vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim. Praesent euismod nunc
eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam
vulputate metus eu enim. Vestibulum pellentesque felis eu massa.
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus tincidunt ultrices.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst. Inte-
ger tempus convallis augue. Etiam facilisis. Nunc elementum fermentum wisi. Aenean placerat.
Ut imperdiet, enim sed gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus eget
enim. Nunc vitae tortor. Proin tempus nibh sit amet nisl. Vivamus quis tortor vitae risus porta
vehicula.
Fusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibus semper, leo velit
ultricies tellus, ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam pellentesque, augue
quis sagittis posuere, turpis lacus congue quam, in hendrerit risus eros eget felis. Maecenas eget
erat in sapien mattis porttitor. Vestibulum porttitor. Nulla facilisi. Sed a turpis eu lacus com-
modo facilisis. Morbi fringilla, wisi in dignissim interdum, justo lectus sagittis dui, et vehicula
libero dui cursus dui. Mauris tempor ligula sed lacus. Duis cursus enim ut augue. Cras ac magna.
Cras nulla. Nulla egestas. Curabitur a leo. Quisque egestas wisi eget nunc. Nam feugiat lacus vel
est. Curabitur consectetuer.
7.2. Another environment with purely minted 33
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu. Ae-
nean faucibus pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel, nisl. Ut
lectus eros, malesuada sit amet, fermentum eu, sodales cursus, magna. Donec eu purus. Quisque
vehicula, urna sed ultricies auctor, pede lorem egestas dui, et convallis elit erat sed nulla. Donec
luctus. Curabitur et nunc. Aliquam dolor odio, commodo pretium, ultricies non, pharetra in,
velit. Integer arcu est, nonummy in, fermentum faucibus, egestas vel, odio.
Sed commodo posuere pede. Mauris ut est. Ut quis purus. Sed ac odio. Sed vehicula hendrerit
sem. Duis non odio. Morbi ut dui. Sed accumsan risus eget odio. In hac habitasse platea dictumst.
Pellentesque non elit. Fusce sed justo eu urna porta tincidunt. Mauris felis odio, sollicitudin sed,
volutpat a, ornare ac, erat. Morbi quis dolor. Donec pellentesque, erat ac sagittis semper, nunc
dui lobortis purus, quis congue purus metus ultricies tellus. Proin et quam. Class aptent taciti
sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Praesent sapien turpis,
fermentum vel, eleifend faucibus, vehicula eu, lacus.
Aenean placerat. Ut imperdiet, enim sed gravida sollicitudin, felis odio placerat quam, ac
pulvinar elit purus eget enim. Nunc vitae tortor. Proin tempus nibh sit amet nisl. Vivamus
quis tortor vitae risus porta vehicula.
Fusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibus semper, leo
velit ultricies tellus, ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam pellentesque,
augue quis sagittis posuere, turpis lacus congue quam, in hendrerit risus eros eget felis.
Maecenas eget erat in sapien mattis porttitor. Vestibulum porttitor. Nulla facilisi. Sed a
turpis eu lacus commodo facilisis. Morbi fringilla, wisi in dignissim interdum, justo lectus
sagittis dui, et vehicula libero dui cursus dui. Mauris tempor ligula sed lacus. Duis cursus
enim ut augue. Cras ac magna. Cras nulla. Nulla egestas. Curabitur a leo. Quisque egestas
wisi eget nunc. Nam feugiat lacus vel est. Curabitur consectetuer.
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu.
Aenean faucibus pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel,
nisl. Ut lectus eros, malesuada sit amet, fermentum eu, sodales cursus, magna. Donec eu
purus. Quisque vehicula, urna sed ultricies auctor, pede lorem egestas dui, et convallis elit
erat sed nulla. Donec luctus. Curabitur et nunc. Aliquam dolor odio, commodo pretium,
ultricies non, pharetra in, velit. Integer arcu est, nonummy in, fermentum faucibus, egestas
vel, odio.
Sed commodo posuere pede. Mauris ut est. Ut quis purus. Sed ac odio. Sed vehicula hendre-
rit sem. Duis non odio. Morbi ut dui. Sed accumsan risus eget odio. In hac habitasse platea
dictumst. Pellentesque non elit. Fusce sed justo eu urna porta tincidunt. Mauris felis odio,
sollicitudin sed, volutpat a, ornare ac, erat. Morbi quis dolor. Donec pellentesque, erat ac
sagittis semper, nunc dui lobortis purus, quis congue purus metus ultricies tellus. Proin et
quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hyme-
naeos. Praesent sapien turpis, fermentum vel, eleifend faucibus, vehicula eu, lacus.Lorem
ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu
tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra
ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,
malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius
orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget
orci sit amet orci dignissim rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non
justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor
sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac
orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum
sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam
tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristi-
que, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Pha-
sellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie
vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accu-
msan nec, suscipit a, ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat
lorem. Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel magna. Integer non
enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cursus
7.2. Another environment with purely minted 35
pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis
eu massa.
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus tincidunt ultri-
ces. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dic-
tumst. Integer tempus convallis augue. Etiam facilisis. Nunc elementum fermentum wisi.
Aenean placerat. Ut imperdiet, enim sed gravida sollicitudin, felis odio placerat quam, ac
pulvinar elit purus eget enim. Nunc vitae tortor. Proin tempus nibh sit amet nisl. Vivamus
quis tortor vitae risus porta vehicula.
Fusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibus semper, leo
velit ultricies tellus, ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam pellentesque,
augue quis sagittis posuere, turpis lacus congue quam, in hendrerit risus eros eget felis.
Maecenas eget erat in sapien mattis porttitor. Vestibulum porttitor. Nulla facilisi. Sed a
turpis eu lacus commodo facilisis. Morbi fringilla, wisi in dignissim interdum, justo lectus
sagittis dui, et vehicula libero dui cursus dui. Mauris tempor ligula sed lacus. Duis cursus
enim ut augue. Cras ac magna. Cras nulla. Nulla egestas. Curabitur a leo. Quisque egestas
wisi eget nunc. Nam feugiat lacus vel est. Curabitur consectetuer.
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu.
Aenean faucibus pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel,
nisl. Ut lectus eros, malesuada sit amet, fermentum eu, sodales cursus, magna. Donec eu
purus. Quisque vehicula, urna sed ultricies auctor, pede lorem egestas dui, et convallis elit
erat sed nulla. Donec luctus. Curabitur et nunc. Aliquam dolor odio, commodo pretium,
ultricies non, pharetra in, velit. Integer arcu est, nonummy in, fermentum faucibus, egestas
vel, odio.
Sed commodo posuere pede. Mauris ut est. Ut quis purus. Sed ac odio. Sed vehicula
hendrerit sem. Duis non odio. Morbi ut dui. Sed accumsan risus eget odio. In hac habitasse
platea dictumst. Pellentesque non elit. Fusce sed justo eu urna porta tincidunt. Mauris felis
odio, sollicitudin sed, volutpat a, ornare ac, erat. Morbi quis dolor. Donec pellentesque, erat
ac sagittis semper, nunc dui lobortis purus, quis congue purus metus ultricies tellus. Proin
et quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos
hymenaeos. Praesent sapien turpis, fermentum vel, eleifend faucibus, vehicula eu, lacus.
another some
hello world
content...
PEP 8 for Beautiful Code
PEP 8, is a guidelines document which focusses on writing Python code to achieve good readability and consis-
tency.
Code is written once and read many times so readability helps the review and hence the longevity of Code us-
age. If the application developed is readable it shows professionalism, which gives a great break in career for a
successful developer.
PEP 8 recommendations
Names choice Names of variables shall explicitly represent for which part it is playing in the
application. Single character, word or words clearly show the function of the
variable in the application.
Naming style shall follow these conventions to make Code clearer and readable in defining
names of variables, functions, classes, etc.
37
38 PEP 8 for Beautiful Code
This book is more of a write-up notes for my memory, rather than a full blown text Book. Kindly bear with this,
as it needs frequent reference of other text books and the Internet.
Development of web applications using a set of the following open source technologies is explained to the best of
my knowledge. The technologies are:
Server Scripting Python based framework, Django for developing MVT based application
OS Linux internals
39
Solutions to the Exercises
Chapter 1
1.1.
#!/usr/bin/env python
a = input()
b = input()
1.2.
41
42 Solutions to the Exercises
Chapter 2
2.1.
Chapter 3
44 Solutions to the Exercises
Chapter 4
4.1.
#!/usr/bin/env python
Index
Check, i
operators, 14