Python Packages

  • By Sneha Ranbhidkar
  • January 24, 2023
  • Python
Python Packages

Python Packages

In this blog, you will get to know what is meant by Python packages.

Packages are a platform that performs a big part of the role in our Python program.

Let’s get to know more then . . . . . . . .

 Mostly what happens is that we organize our data in folders or sub-folders in file format. So that due to this we can easily gate our data while searching. SevenMentor is the best Python Classes in Pune, and offers industry-oriented Python Training in Pune

This is the same procedure followed by a package it means a package takes Python in a modular approach which is the next logical level in the programming world.

 

For Free, Demo classes Call: 02071171500

Registration Link: Click Here!

 

As we know that module contains functions, methods, algorithms, classes, objects. Etc. so a package contain relevant modules. 

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

Python Packages

So let’s start to create a package :  > > >  > >  > > > > > > >

Following are the steps to create a package: :

Step 1 :

Create a new folder in F : > myappln

Step 2 : 

Inside that folder create a sub folder named as mypackge

Step 3 :

Inside that folder create a blank file named as __init__.py

Step 4 :

Now create modules like greet.py and fun.py with help of following code :

Greet.py

Def greeting ( name ) :

Print ( “ hello “, name )

Fun.py

Def sum (q , p ) :

Return q + p

Def average ( r, s ) :

return ( r + s ) / 2

Def power ( t , u ) :

Return t * * u

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – 

 

For Free, Demo classes Call: 02071171500

Registration Link: Click Here!

 

So now its time to check where we create the package by our own so its working successfully or not . . . . ? 

For that what we need to do is go through conitue steps :

 Step 5 : Go to command prompt and enter directory :

Step 6 :  Change your directory like this :

C:> cd f:

F:> cd myappln

F : / myappln : > python

Step 7 : Now its time to import our package

> > >  from mypackge import fun

> > >  fun . power( 3 , 2 )

9

So this is the way to create your own package and implement in program . like this we can call our another functions also which are defined in program :

> > >  fun . average ( 4 , 6 )

5

Next function is :

>  > > fun . sum ( 5 , 9 )

11

The another way to write the program is like 

> > from mypakge . fun import sum

> >  > sum ( 3, 6 )

 

For Free, Demo classes Call: 02071171500

Registration Link: Click Here!

9

> > > from mypackge . fun import average

> > > > > > >  average ( 8 , 6 )

7

> > > from mypackge . fun import power

> > >  >  > > >  power ( 2 , 4 )

16

 

Author:-

Sneha Ranbhidkar
Call the Trainer and Book your free demo Class For Python Call now!!! | SevenMentor Pvt Ltd.

© Copyright 2021 | SevenMentor Pvt Ltd.

Submit Comment

Your email address will not be published. Required fields are marked *

*
*