Student Activity
Student Activity Guide:
1) Overview of Commonly Used Python Libraries
Explore key Python libraries such as
requests,re, anddatetime.Learn when and why to use these libraries in practical applications.
Student Exercise: Research and list five additional Python libraries and their use cases.
2) Using the Requests Library for HTTP Requests
Learn how to make GET and POST requests using the
requestsmodule.Understand handling JSON responses from APIs.
Example Code:
import requests
# Making a GET request
response = requests.get("https://jsonplaceholder.typicode.com/users")
if response.status_code == 200:
users = response.json()
print(users)Student Exercise: Modify the code to make a POST request with dummy JSON data.
3) Regular Expressions with the re Module
re ModuleUse regular expressions for pattern matching in text.
Learn common regex functions:
match(),search(),findall(), andsub().
Example Code:
import re
text = "My email is [email protected]"
pattern = r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}"
match = re.search(pattern, text)
if match:
print("Found email:", match.group())Student Exercise: Write a regex pattern to extract phone numbers from a given text.
4) Working with the Datetime Module
Learn to handle date and time data efficiently.
Convert string dates into
datetimeobjects and format them.
Example Code:
from datetime import datetime
# Get current date and time
now = datetime.now()
print("Current Date and Time:", now.strftime("%Y-%m-%d %H:%M:%S"))Student Exercise: Write a function that calculates the difference in days between two given dates.
Last updated