2. PACKAGES / LIBRARY
In Computer we store files in organized hierarchies
Subdirectories
Files
Large projects in Python are organized as Packages
which consists of many
Sub-Packages
Similar Modules
Packages makes projects easy to manage and conceptually clear
2
3. PACKAGES / LIBRARY
Python package is a directory containing
Sub-packages
Modules
Along with an __init__.py file
Python module
Is a . py file
Contains functions, variables
3
double underscore
5. • Game Development Package Organization
Eg 2.PACKAGES / LIBRARY
5
PACKAGE
list
SUBPACKAGES
M
O
D
U
L
E
S
6. • Steps to create a package
– Create a directory with the package name
– Create modules under it
– Create a file __init__.py in the directory
Note : File __init__.py is a simple file required to make python treat the
directory on the disk as packages of python
• Access packages and its modules
– from PACKAGE_NAME import MODULE_NAME
• Access functions in modules
– Use dot operator “ . ”
– MODULE_NAME . FUNCTION_NAME
PACKAGES / LIBRARY
6
10. To Access Packages and its Modules
from mensuration import square,rectangle
To Access functions inside the Modules
square . area (side)
rectangle . area (length,breadth)
PACKAGES / LIBRARY
10
#Rectangle Module
def area(length,breadth):
def peri(length,breadth):
# Square Module
def area(side):
def peri(side):
11. 1. Package in Python is a
– (a) File
– (b) Database
– (c) hierarchical file directory
– (d) hierarchical database directory
»(Ans: c)
11
12. 2. To include a package in python we use
– (a) include statement
– (b) import statement
– (c) package include statement
– (d) package import statement
»(Ans: b)
12
13. 3. A Package contains
– (a) sub-packages
– (b) modules
– (c)__init__.py
– (d) All the above
»(Ans: d)
4. Python supports built in packages
– (a) Yes
– (b) No
»(Ans: a)
13
14. 5. The package folder contains a special file
called__________
– (a) __init__.py,
– (b) Pack_.py
– (c)_pack_,py
– (d)_init_pack_.py
»(Ans: a)
14
16. Data structure
way to store and organize data
helps in writing efficient programs in any
language
Python is a high-level, interpreted, interactive
and object-oriented scripting language using
which we can study the fundamentals of data
structure in a simpler way as compared to
other programming languages.
Data structure in Python
16
17. Data structure in Python
17
Data Structures in Python
Built-in Data Structures User-Defined Data Structures
List
Tuple
Dictionary
Set
Stack
Queue
Tree
Graph
Linked
list
18. Today we will focus on few Data Structures
1.Stacks
2.Queues
3.Graph
Data structure in Python
18
20. Stack
is an ordered collection of items
addition of new items
removal of existing items
this ordering principle is called Last-In First-Out(LIFO)
A Stack of Books A Stack of Primitive Python Objects
Data structure - Stack
20
always takes place at the same end
usually top
21. Data structure - Stack
21
Stack
Insertion
“PUSH”
Deletion
“POP”
Top
LIFO PRINCIPLE
23. Stack using LIST in Python
Example:
# empty stack
stack = [ ]
# push operation # pop operation
23
OUTPUT
stack.append(10) stack =[10]
stack.append(20) stack =[10,20]
stack.append(30) stack =[10,20,30]
OUTPUT
stack.pop() stack =[10,20,30]
stack.pop() stack =[10,20]
top
top
top
top
top
25. Queue
is an ordered collection of items
Addition of new items happens at one end, called the “rear,”
Removal of existing items occurs at the other end, called the “front.”
This ordering principle is sometimes called First-In First-Out (FIFO)
A Queue of Python Data Objects
Data structure - Queue
25
33. 1. Consider the following operation performed on a stack
Push(1);
Pop();
Push(2);
Push(3);
Pop();
Push(4);
Pop();
After the completion of all operation, the number of elements
present in stack are
- (a) 1
- (b) 2
- (c) 3
- (d) 4
»(Ans: a)
33
34. 2. A list of elements in which deletion can be
done from one end (front) and insertion can
take place only at the other end (rear) is known
as
- (a) Queue
- (b) Stack
- (c) Tree
- (d) Linked list
»(Ans: a)
34
35. 3. Google Map is an application of
- (a) Tree
- (b) Stack
- (c) Graph
- (d) Queue
»(Ans: c)
35