2. Matching patterns
Definition Program
Regular expressions are
complicated mini-language. They
rely on special characters to
match unknown strings, but let's
start with literal characters, such
as letters, numbers, and the space
character, which always match
themselves.
The “re” module which comes
with every python installation
provides regular expression
support.
import re
search_string = "Techno Plus Logic"
pattern = "Tec"
match = re.match(pattern,
search_string)
if match:
print("Pattern Found ",
match.group())
else:
3. Math functions
Definition Program
Python has a math module that
provides most of the familiar
mathematical functions. A
module is a file that contains a
collection of related functions.
Before we can use the module,
we have to import it:
>>> import math
print(math.sin(45))
print(math.tan(45))
print(math.cos(45))
print(math.log10(45))
print(math.sqrt(4))
print(math.ceil(4.55565))
print(math.degrees(45))
print(math.pow(4,5))
4. Internet Access
Definition
Checking Internet Connection in
Python
Nowadays, the Internet is an
essential part of our day-to-day
lives. If the server is down even for
a minute, then we check the Internet
connectivity in various ways. Can
Python help us check the
connectivity? Yes, we can use
Python language for checking the
internet connection. In this tutorial,
we will find out whether the
computer is connected to the internet
or not.
1. using urllib package.
2. using an IP address/socket
package.
5. Date & Time:
Definition
The types of objects in datetime are
as below.
In python, datetime is a module
which provides different classes
to work with dates and times.
date
time
datetime
timedelta
tzinfo
timezone
6. Date Object: Pragram
Date object depicts the date as
date(year, month, day) in an ideal
Gregorian calendar. Syntax of the
Date class is represented as
below.
Syntax:
class
datetime.date(year,month,day)
>>> from datetime import date
# method today() shows the today's date
>>> today=date.today()
>>> today
datetime.date(2017, 11, 7)
>>> x=d.timetuple()
>>> today=x
>>> x
time.struct_time(tm_year=2017, tm_mon=8,
tm_mday=15, tm_hour=0, tm_min=0, tm_sec=0,
tm_wday=1, tm_yday=227, tm_isdst=-1)
# assigning the date
>>> d=date(2017,11,7)
7. Multithreading
Concept Definition
In computing, a process is an
instance of a computer program that
is being executed. Any process has 3
basic components:
An executable program.
The associated data needed by the
program (variables, work space,
buffers, etc.).
The execution context of the
program (State of process).
A thread is an entity within a process
that can be scheduled for execution.
Also, it is the smallest unit of
processing that can be performed in an
OS (Operating System).
In simple words, a thread is a sequence
of such instructions within a program
that can be executed independently of
other code. For simplicity, you can
assume that a thread is simply a subset
of a process!
8. A thread contains all this information in a Thread
Control Block (TCB):
Thread Identifier: Unique id (TID) is assigned to every new thread
Stack pointer: Points to thread’s stack in the process. Stack contains the
local variables under thread’s scope.
Program counter: a register which stores the address of the instruction
currently being executed by thread.
Thread state: can be running, ready, waiting, start or done.
Thread’s register set: registers assigned to thread for computations.
Parent process Pointer: A pointer to the Process control block (PCB) of
the process that the thread lives on.
9. Data compression
Definition Program
Data compression is the process of
modifying, encoding or converting
the bits structure of data in such a
way that it consumes less space on
disk. It enables reducing the storage
size of one or more data instances or
elements. Data compression is also
known as source coding or bit-rate
reduction.
Zip is the build-in.
>>> import zlib
>>> s = b'you learn learnt learning
the data daily '
>>>len(s)
41
>>>
>>> t = zlib.compress(s)
>>>len(t)
39
10. GUI Interface
Definition
Tkinter is the standard GUI
library for Python. Python when
combined with Tkinter provides a
fast and easy way to create GUI
applications. Tkinter provides a
powerful object-oriented interface
to the Tk GUI toolkit.
Import Tkinter in program.
Sr.No. Operator
1
Button
2
Canvas
3
Checkbutton
4
Entry
5
Frame
6
Label
7
Listbox
8
Menubutton
9
Menu
10
Message
11. Turtle Programming
Definition
“Turtle” is a Python feature like a
drawing board, which lets us
command a turtle to draw all over
it! We can use functions like
turtle.forward(…) and
turtle.right(…) which can move
the turtle around. Commonly
used turtle methods are.
Import turtle in program.
METHOD
Turtle()
forward()
backward()
right()
left()
penup()
pendown()
up()
down()
color()
13. Testing
Definition
Unit Test
Testing determines whether
software runs correctly based on
specific inputs and identifies
defects that need to be fixed.
Unit Testing in Python is done to
identify bugs early in the
development stage of the
application when bugs are less
recurrent and less expensive to
fix. A unit test is a scripted code
level test designed in Python to
verify a small "unit" of
functionality.
14. Why is testing important?
As software scales in codebase size, it's impossible for a person or even a large team to
keep up with all of the changes and the interactions between the changes. Automated
testing is the only proven method for building reliable software once they grow past the
point of a simple prototype. Many major software program development failures can be
traced back to inadequate or a complete lack of testing.
It's impossible to know whether software works properly unless it is tested. While
testing can be done manually, by a user clicking buttons or typing in input, it should be
performed automatically by writing software programs that test the application under
test.
There are many forms of testing and they should all be used together. When a single
function of a program is isolated for testing, that is called unit testing. Testing more than
a single function in an application at the same time is known as integration testing. User
interface testing ensures the correctness of how a user would interact with the software.
There are even more forms of testing that large programs need, such as load
testing, database testing, and browser testing (for web applications).
15. Writing and Running Test case
Create a file named tests.py in the folder named “tests”.
In tests.py import unittest.
Create a class named TestClass which inherits from the class unittest.
TestCase.
Create a test method
To run the tests, we just defined, we need to call the method unittest.