Python Package
Python Package
𝘽U𝙄L𝘿-
𝙋𝘼𝘾𝙆𝘼GES
𝙄N
Presented by Saniya sawardear & Riya
1
mohite
INTRODUCTION
2
US𝙄NG 𝙋𝙔𝙏𝙃ON 𝘽U𝙄L𝘿-𝙄N 𝙋𝘼𝘾𝙆𝘼GES:
Python comes with a variety of built-in libraries, often referred to as the standard library. These
libraries provide functionalities for various tasks, such as handling file operations, interacting with the
operating system, data manipulation, and much more. Below is an overview of the most commonly
used built-in packages and modules available in Python:
1.𝙤𝙧
𝙋𝙪𝙧𝙥𝙤𝙨𝙚: Interacting with the operating system
F𝙪𝙣𝙘𝙩𝙞𝙤𝙣: File and directory manipulation, process management, environment etc variables,
E𝙭𝙖𝙢𝙥𝙡𝙚:
Import os
os.mkdir("new_folder") # Creates a new directoryos remove ("file.txt") # Removes
a File
3
2.𝙨𝙮𝙨
F𝙪𝙣𝙘𝙩𝙞𝙤𝙣: Handling command -line arguments,interacting with the interpreter,managing paths, etc.
E𝙭𝙖𝙢𝙥𝙡𝙚:
𝙄mport sys
Print(sys.argv) # List of command-line arguments sys.exit(0) # Exit the program
3. 𝙢𝙖𝙩𝙝
E𝙭𝙖𝙢𝙥𝙡𝙚:
𝙄mport math
Print(math.sqrt(16)) # Output: 4
4.0
4.𝙧𝙖𝙣𝙙𝙤𝙢
F𝙪𝙣𝙘𝙩𝙞𝙤𝙣𝙨: Random number generation, shuffling, choosing random elements from a list, etc
E𝙭𝙖𝙢𝙥𝙡𝙚
import random
print(random.randint(1.10)) # Random number between 1 and 10 print (random.choice([1,2,3,4])) # Random choice from a
list
5.𝙙𝙚𝙩𝙚𝙩𝙢
𝙞𝙚
E𝙭𝙖𝙢𝙥𝙡𝙚
import datetime
print(datetime.datetime.now()) # Get the current date and 5
time print(datetime.date.today()) # Get today's date
6.𝙧𝙚
E𝙭𝙖𝙢𝙥𝙡𝙚:
import re
Pattern = r"\
d+"
text = "There are 123 apples" result = re.findall(pattern,
text) print(result) # Outputs: ['123']
7.𝙨
𝙟𝙤𝙣
E𝙭𝙖𝙢𝙥𝙡𝙚
Import os.path
print(os.path.exists("file.txt")) # Check if file
exists print(os.path.join("folder","file.txt")) # Join
paths
9. 𝙩𝙢
𝙞𝙚
import itertools
print(list(itertools.permutation([1,2,3,]))) # All permutations
11.𝙛
𝙪𝙣𝙘𝙩𝙤𝙤𝙨
𝙡
E𝙭𝙖𝙢𝙥𝙡𝙚
import functools
def add(x, y):
return x + y
add_five = 8
functools.partial(
add, 5)
12.𝙘𝙤
𝙚
𝙡𝙘𝙤
𝙩𝙞𝙣𝙨
13.𝙘𝙨𝙫
𝙋 𝙪𝙘𝙩𝙤
𝙛𝙪𝙣 𝙧𝙞𝙥 𝙚: Reading
𝙣𝙤𝙨Handling from
CSV fileand
format in a structured way.
writing
E𝙭𝙖𝙢𝙥𝙡𝙚to : CSV files.
Import csv
with open('data.csv', mode='r') as
file: csv_reader = csv.reader(file)
for row in 9
csv_reader:
print(row),
14. 𝙨𝙤𝙘𝙠𝙚𝙩
E𝙭𝙖𝙢𝙥𝙡𝙚
mport socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('example.com', 80))
15. 𝙝𝙩𝙥
E𝙭𝙖𝙢𝙥𝙡𝙚
import argparse
parser = argparse.ArgumentParser(description="A simple argument
parser") parser.add_argument("name", help="Name of the user")
args = parser.parse_args()
print(f"Hello, {args.name}")
17. 𝙥
𝙘
𝙞𝙠
𝙚
𝙡
E𝙭𝙖𝙢𝙥𝙡𝙚
import shutil
shutil.copy("source.txt", "destination.txt") # Copy a file
19.𝙥𝙖
𝙡𝙩𝙛𝙤𝙧𝙢
E𝙭𝙖𝙢𝙥𝙡𝙚
import platform
1
print(platform.system()) # Outputs the OS type (e.g.,
2
'Windows')
20. 𝙩𝙝𝙧𝙚𝙖𝙙𝙣
𝙞𝙜
E𝙭𝙖𝙢𝙥𝙡𝙚
import
threading def
print_hello():
print("Hello
from thread!")
thread = threading.Thread(target=print_hello)
thread.start()
1
3
INSTALLING PACKAGES USING PIP :
To install packaoftes usinoft pip, follow this
step:-
Example:
pip install 1
4
requests
3.𝙄𝙣𝙨𝙩𝙖𝙡 𝙖 𝙨𝙥𝙚𝙘
𝙛𝙞 𝙫𝙚𝙧𝙨𝙤
𝙞𝙣 𝙤𝙛 𝙖 𝙥𝙖
𝙖𝙜𝙚
𝙠𝙘 𝙨:
E𝙭𝙖𝙢𝙥𝙡𝙚:
4. 𝙄𝙣𝙨
𝙖
𝙩𝙡𝙡 𝙢𝙪𝙥
𝙩𝙞𝙡𝙚
𝙡 𝙥𝙖𝙘𝙠𝙖𝙜𝙚𝙨 𝘼𝙩 𝙤
𝙣𝙚𝙘:
If you have a requirements.txt file (common for project dependencies), you can install all
the packages listed in it:
6. 𝙐𝙥𝙜𝙧𝙖𝙙𝙚 𝙖𝙣 𝙚𝙭
𝙨
𝙞𝙣
𝙩𝙞𝙜 𝙥𝙖𝙘𝙠𝙖𝙜𝙚𝙨:
E𝙭𝙖𝙢𝙥𝙡𝙚:
1
pip install --upgrade 6
requests
𝙏𝙝𝙖𝙣𝙠
𝙔𝙤𝙪
1
7