Using Python Libraries
Using Python Libraries
Using Python Libraries
By PathWala / PortalExpress-
for importing selected items.
To import entire module syntax is -
import <module 1 >, <module 2>....
For example:
import time
import decimals, fractions
For Example :-
import math as a
a.sqrt (16)
By PathWala / PortalExpress-
from <module name >import<object name>
For example:
from math import sqrt
For example: -
from math import sqrt, pi, pow
For example:-
len(),str(),type()
math module, random module , etc.
By PathWala / PortalExpress-
By PathWala / PortalExpress-
By PathWala / PortalExpress-
Python's built in string functions: -
That are ---
(I) If the string based iterator is a string then the <str> is inserted after
By PathWala / PortalExpress-
every character of the string.
For example:
>>>"***". join ("Hello")
'H***e***l***l***o'
(ii) If the string based iterator is a list or tuple of string then, the given
string / character is joined with each member of the list or tuple, But
the list or tuple must have all member as strings otherwise Python will
raise an error.
(i) If you do not provide any argument to split then by default it will
split the give string considering whitespace as a separator.
For example:
>>>"I Love Python". split()
['I', 'Love', 'Python']
By PathWala / PortalExpress-
the given string is divided into parts considering the given
string/character as separate and separator character is not included in
the split string.
For example:
>>>"I Love Python". split ("o")
['I L','ve Pyth','n']
For example:
>>>"I Love Python". replace ("Python", "Programming")
>>>"I Love Programming"
USING RANDOM MODULE: -
Python has a module namely random that provides random number
generators.
To use random number generators in your Python program, you first
need to import module random using any import command
import random
By PathWala / PortalExpress-
random.uniform(a, b) : - It returns a random floating point number N
such that
a ≤ N ≤ b for a ≤ b and
b ≤ N ≤ a for b < a and
import string
By PathWala / PortalExpress-
For example: -
>>>import string
>>>string.digits
'0123456789'
By PathWala / PortalExpress-
At first you have known a path where all files of python saved.
You can find the path of python by following command as shown in
figure:-
By PathWala / PortalExpress-
Now make another folder (Sub Package) in package folder; if you
want
For example we make portal_express (sub package)
By PathWala / PortalExpress-
Like that:-
Similarly also, make an empty module with name __init__.py in
pathwala(package)
By PathWala / PortalExpress-
And save that module in pathwala (Package)
By PathWala / PortalExpress-
Now, Your package become ready to use in Python
For example as shown in figure: -
Thankyou!!!!!
By PathWala / PortalExpress-